- 写了个shell脚本监听日志变化,grep Exception发送邮件通知,直接把代码贴出来,也可以到我的git地址 https://github.com/kittaaron/blog/blob/master/sendmail.sh 查看。注意:需要先安装mailx(yum install mailx)。
- 给公众号(三岁嘟嘟)打下广告:
#!/bin/bash #-------------------------------------------- # 监听服务器日志, 如果出现错误,发邮件告警 # author:kittaaron # site: http://kittaaron:1888/static/index.html #-------------------------------------------- cd `dirname $0` logfile='logs/out_sports.log' beforelinenum=`sed -n '$=' logs/out_sports.log` echo $beforelinenum echo "开始监听..." secondspan=3 ip=`ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/,