版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/miss1181248983/article/details/84343631
要实现错误日志记录,当有新的错误日志产生时,能第一时间在新文件中记录下来。
这里以nginx错误日志为例,
内容如下:
#!/bin/bash
##This script is used for log alerts
a=`grep "error" /usr/local/nginx/logs/error.log | sort -n | tail -1 | awk '{ print $0 }'`
b=`cat /tmp/nginx.log | wc -l`
c=`grep "error" /usr/local/nginx/logs/error.log | sort -n | tail -1 | awk '{ print $1 $2 }'`
d=`grep "error" /tmp/nginx.log | sort -n | tail -1 | awk '{ print $1 $2 }'`
if [ "$b" -eq 0 ];then
echo $a > /tmp/nginx.log
exit 1
else
if [ "$c" = "$d" ];then
echo "This error has been warned."
exit 0
else
echo $a >> /tmp/nginx.log
exit 1
fi
fi
针对返回结果,感觉可以加入到zabbix来实现邮件中有具体错误内容的告警。