# 发送邮件 mail -s "主题" 收件人 < message # 查看新邮件 mail # 查看归档邮件 mail -f
# 开始脚本 #!/bin/bash
# 1. 检查 linux 可用内存,内存小于100M时,发邮件给运维 # 2. 加入crontab, 每三分钟检查一次 FreeMem=`free -m | awk 'NR==2 {print $NF}'` CHARS="Current memory is $FreeMem"
if [ "$FreeMem" -lt 12000 ]; then echo$CHARS | tee /tmp/message.txt mail -s "`date +%F-%T` $CHARS" feng@laptop-b4fc2bhq.localdomain < /tmp/message.txt echo"内存不足" fi
# MySQL 监控脚本,只写一种,其他的类似 if [ `netstat -nltp | grep 3306 | wc -l` = "1" ]; then echo"MySQL is running!!!" else echo"MySQL is stop, Start now..." systemctl start mariadb fi