实现错误日志记录
16lz
2021-04-25
要实现错误日志记录,当有新的错误日志产生时,能第一时间在新文件中记录下来。
这里以nginx错误日志为例,
内容如下:
#!/bin/bash##This script is used for log alertsa=`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来实现邮件中有具体错误内容的告警。
©著作权归作者所有:来自51CTO博客作者80民工的原创作品,如需转载,请注明出处,否则将追究法律责任更多相关文章
- 使用mysqlbinlog查看二进制日志
- 日志易AIOps实践:日志数据大有用途
- 备份系统建设中的四个误区和六个错误
- zabbix server 内存溢出 @第一次遇到
- MySQL日志详细说明
- MySQL事务之-2
- 日志收集系统elk
- 备份实战案例2
- DLC