crond+mail+shell实现的错误日志监控并发送邮件通知shell脚本

@KenRitchie Linux  2018-08-30 20:53 预计阅读1分钟

#尽量用绝对路径,相对路径在crond里面是有问题的
log_name=$(date +%Y\/%m\/%d)
#tail -f /usr/local/nginx/logs/error.log  |grep -C 10 error >>${time_log}.log
#content=$(sed -n "/$(date +%Y\/%m\/%d)/,/2018\/08\/31/p"  /usr/local/nginx/logs/error.loga)
logline=$(wc -l /usr/share/nginx/logs/https_api_school_nginx_error.log)
sed -n "/$(date +%Y)\/$(date +%m)\/$(date +%d)/,/2119\/08\/30/p" /usr/share/nginx/logs/https_api_school_nginx_error.log >>/usr/share/nginx/logs/school_err.log
if [  -s /usr/share/nginx/logs/school_err.log ]; then
  cat /usr/share/nginx/logs/school_err.log |mail -s "【xxxxxx】${log_name}错误日志,请排查。" wangda@xxxxx
  cat /usr/share/nginx/logs/school_err.log |mail -s "【xxxxxx】${log_name}错误日志,请排查。" chencf@xxxxx
  cat /usr/share/nginx/logs/school_err.log |mail -s "【xxxxxx】${log_name}错误日志,请排查。" zhuliang@xxxx
fi
if [  -s "../logs/xmsj_err.log" ]; then
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" chencf@xxxx
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" zhangqi@xxxx
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" pengjk@xxxxx
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" lijb@xxxxx
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" taolb@xxxxx
  cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【xxxx】${log_name}错误日志,请排查。" zhuliang@xxxxx
fi


TOTAL COMMENTS: 3+1

  1. wangda
    22day ago

    可以

    [0] XX [0] 回复
  2. qerqr
    31day ago

    ok

    [0] XX [0] 回复
  3. qerqr
    31day ago

    #! /bin/bash
    log_name=$(date +%Y\/%m\/%d)
    logline=$(wc -l /usr/share/nginx/logs/https_api_school_nginx_error.log)
    contents=$(cat /usr/share/nginx/logs/https_api_school_nginx_error.log |grep "$(date +%Y)\/$(date +%m)\/$(date +%d)" | tail -n 10)
    if [[ $contents ]]; then
      echo $contents |mail -s "【校园xxxxxx(主)】${log_name}错误日志,请排查。" xxxxx@xiaoma.wang
    fi
    if [  -s /usr/share/nginx/logs/xmsj_err.log ]; then
      cat /usr/share/nginx/logs/xmsj_err.log |mail -s "【小码xx】${log_name}错误日志,请排查。" xxxxx@xiaoma.wang
    fi

    [0] XX [0] 回复

发表评论

点击发布 / 未登录?