码迷,mamicode.com
首页 > 其他好文 > 详细

邮件报警脚本

时间:2019-02-20 13:18:21      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:==   awk   name   res   netstat   processor   sendmail   mail   mct   

#!/bin/bash
#安装邮件
rpm -q sendmail
 if [ $? -ne 0 ];then
         yum -y install sendmail
 fi
rpm -q mutt
 if [ $? -ne 0 ];then
         yum -y install mutt
 fi
systemctl restart sendmail
#设置变量
HOST=`hostname`
SYS=`uname -a`
DATE=`date "+%F %H:%M:%S"`
CPU=`cat /proc/cpuinfo |grep processor | wc -l`
ID=`vmstat | awk ‘NR==3{print $15 }‘`
WA=`vmstat | awk ‘NR==3{print $16 }‘`
LOAD=`w | awk ‘NR==1{print $8}‘ |awk -F "," ‘{print $1}‘`
DISK=`df |awk ‘{if(NR==7){print int($5)}}‘`
FREE=`free -m | awk ‘NR==2{print $4}‘`
CACHE=`free -m | awk ‘NR==2{print $7}‘`
TCP=`netstat -atunlp`
IF=`iftop -i ens33 -P -Nn -L 100 -s 1 -t`
#cpu报警
 if [ $CPU -eq 4 ];then
  echo "wa=$WA and id=$ID cpu processor is ok"
 else
  echo "wa=$WA and id=$ID cpu processor have problem" |mutt -s "SYSTEM-memory" *********@163.com
 fi
 if [ $LOAD -gt 0.05 ];then
  echo "CPU-LOAD is beyond the rate" |mutt -s "CPU-LOAD" ***********@163.com
 else
  echo "CPU-LOAD is ok"
 fi
#磁盘报警
 if [ $DISK -gt 80 ];then
  echo "SYSTEM-DISK is beyond the 80%" |mutt -s "SYSTEM-DISK" ************@163.com
 else
  echo "SYSTEM-DISK is ok"
 fi
#内存报警
memory=$(($FREE+$CACHE))
echo $memory
 if [ $memory -lt 1000 ];then
  echo "SYSTEM-memory less than 1000M " |mutt -s "SYSTEM-memory" *************@163.com
        else
                echo "SYSTEM-memory is ok"
        fi

邮件报警脚本

标签:==   awk   name   res   netstat   processor   sendmail   mail   mct   

原文地址:https://www.cnblogs.com/cuiyupu/p/10405741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!