以前刚开始学shell的时候写的基本监控脚本,不过现在直接使用nagios的插件进行监控了,发出来给大家看看。
1 监控磁盘:
#!/bin/sh
used_disk=`df-h|grep /dev/sda2|awk ‘{print int($5)}‘`
if [$used_disk -gt 90 ]
then
echo "disk is more than 90%,now is$used_disk%."
fi
2 监控内存:
#!/bin/sh
used_mem=`free-m|awk ‘NR==3 {print $NF}‘`
if [$used_mem -lt 1000 ]
then
echo "mem is not enough,$used_mem."
fi
3 监控端口:
#!/bin/sh
port=`netstat-lntup|grep nginx|wc -l`
if [$port -ne 1 ]
then
/application/nginx/sbin/nginx
echo "Nginx is starting."
else
echo "NGINX is running."
fi
4 监控URL:
#!/bin/sh
functioncheck_url(){
curl=`curl -I -s $1|head -1|awk ‘{print $2}‘`
if ["$curl" = "200" ]
then
echo "nginx is ok"
else
echo "nginx is error"
fi
}
check_url$1
原文地址:http://hejianping.blog.51cto.com/11279690/1748659