操作系统:centos 7.2
sendmail 自动报警
#完成时间:2018.04.16
#!/bin/bash
#CPU 1,5,15
###########################################################
if [ -e detection_script ]
then
mkdir -p /detection_script/
fi
############################################################
dt=/detection_script/datetime.txt
cl=/detection_script/cpuload.txt
ct=/detection_script/cputime-$(date +%Y-%m-%d).txt
c3=/detection_script/cpu3.txt
date > $dt
uptime | awk ‘{print $6,$7,$8,$9,$10}‘ > $cl
paste $dt $cl >> $ct
Ip=ip a | grep inet | grep -v inet6 | grep -v 127 | sed ‘s/^[ \t]*//g‘ | cut -d ‘ ‘ -f2
c3=tail -1 $ct | awk ‘{print $10}‘ | awk -F‘.‘ ‘{print $1}‘
if [ $c3 -ge 0 ]
then
echo "dev环境:当前$Ip地址cpu已达到理论峰值 5%
15分值为: $c3" | mail -s "$Ip":CPU异常 [email protected]
fi
原文地址:http://blog.51cto.com/amunlinux/2104037