實現錯誤日誌記錄
阿新 • • 發佈:2018-12-21
要實現錯誤日誌記錄,當有新的錯誤日誌產生時,能第一時間在新檔案中記錄下來。
這裡以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來實現郵件中有具體錯誤內容的告警。