Operating system: CentOS 7.2
SendMail Automatic Alarm
#完成时间: 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 [$c 3-ge 0]
Then
echo "Dev Environment: Current $IP address CPU has reached theoretical peak 5%
15 Score: $c 3 "| Mail-s "$Ip": CPU exception [email protected]
Fi
Centos7.2,shell script monitors CPU and SendMail auto alarm