#!/bin/bash

#定义变量 LOG_FILE="/var/log/syslog" ERROR_COUNT=0

#检查日志文件中是否有错误信息 if grep -q "error" $LOG_FILE; then ERROR_COUNT=$(grep -c "error" $LOG_FILE) fi

#发送邮件通知管理员 if [ $ERROR_COUNT -gt 0 ]; then SUBJECT="[Error Alert] There are $ERROR_COUNT errors in syslog" BODY="Please check the syslog for more details" echo $BODY | mail -s $SUBJECT admin@example.com fi

#记录检测时间和错误数量 echo "$(date) - Found $ERROR_COUNT errors in syslog" >> /var/log/error_check.log

#结束脚本 exit 0

写一段自动检测故障的shell脚本