centos7.2,shell腳本監控CPU並sendmail自動報警
阿新 • • 發佈:2018-04-16
cpu報警 sendmail報警 shell centos 7.2 操作系統:centos 7.2
sendmail 自動報警
#完成時間:2018.04.16 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=
c3=
if [ $c3 -ge 0 ]
then
echo "dev環境:當前$Ip地址cpu已達到理論峰值 5%
15分值為: $c3" | mail -s "$Ip":CPU異常 [email protected]
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
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
centos7.2,shell腳本監控CPU並sendmail自動報警