#!/bin/bash
cpu=`top -b -n 1 | grep -w Cpu | awk '{print$5}'| awk -F '%' '{printf"%d",$1}'`
if [ $cpu -le 50 ]
then
echo "cpu: $((100 - cpu))%" > test.txt
mail -s "服务器紧急, CPU占用率过高!" yourmail@domail.com < test.txt
fi
mem=`top -b -n 1 | grep -w Mem | awk '{printf"%d",$6/$2*100}'`
if [ $mem -le 50 ]
then
echo "Memory: $((100 - mem))%" > test.txt
mail -s "服务器紧急,内存占用率过高!" yourmail@domail.com < test.txt
fi
httpdnum=`ps aux | grep 'httpd' | wc -l`
if [ $httpdnum -le 1 ]
then
echo "服务器紧急,apache进程结束!" > test.txt
mail -s "服务器紧急,apache进程结束!" yourmail@domail.com < test.txt
fi
tomcatnum=`ps aux | grep 'tomcat' | wc -l`
if [ $tomcatnum -le 1 ]
then
echo "服务器紧急,tomcat进程结束!" > test.txt
mail -s "服务器紧急,tomcat进程结束!" yourmail@domail.com < test.txt
fi
简单的Linux服务器监控脚本
最新推荐文章于 2024-06-05 13:45:42 发布