安装mail yum install mail vi /etc/mail.rc 添加配置 set from=XXXX@qq.com set smtp=smtp.qq.com set smtp-auth-user=XXXX@qq.com set smtp-auth-password=qq授权码 set smtp-auth=login

重启postfix service postfix restart

编写shell脚本

#!/bin/bash log_file=/usr/local/iot/nohup.out file=date +%Y%m%d if [ ! -e $log_file ] then echo "send mail" echo "没找到文件$log_file" | mail -s " 启动出现错误" XXX@qq.com YYY@qq.com ZZZ@qq.com else erro_num=cat $log_file|grep 'erro'|wc -l Erro_num=cat $log_file|grep 'Erro'|wc -l if [ $erro_num -gt 0 -o $Erro_num -gt 0 ] then grep -rin 'erro' -A 5 $log_file>/usr/local/iot/ioterror$file.log echo "send mail" echo "请检查文件$log_file" | mail -s "运行时出现错误" -a /usr/local/iot/ioterror$file.log XXX@qq.com YYY@qq.com ZZZ@qq.com fi fi

设置定时任务 */5 * * * * /bin/bash /opt/check.sh