centos7.2,shell脚本监控CPU并sendmail自动报警

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.2,shell脚本监控CPU并sendmail自动报警相关的知识,希望对你有一定的参考价值。

操作系统: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

以上是关于centos7.2,shell脚本监控CPU并sendmail自动报警的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本

使用shell脚本监控少量服务器并发送微信告警信息

Linux shell 脚本监控cpu,内存,硬盘,网络,是否存活

开放系统监控shell脚本

shell脚本监控系统负载CPU和内存使用情况

shell常用监控脚本