简单的Linux服务器监控脚本
(2011-07-13 11:31:36)
标签:
杂谈
#!/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
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。