shell监控脚本-监控磁盘
注意:请先参考 shell监控脚本-准备工做,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控磁盘linux
cat chk_df.sh shell
#!/bin/bash bash
# 运维
#script_name:chk_df.sh ssh
#check disk ide
# 测试
#last update 20130320 by dongnan spa
#bbs# http://bbs.ywwd.net/ .net
#blog# http://dngood.blog.51cto.com code
#
#df -Th
#Filesystem Type Size Used Avail Use% Mounted on
#/dev/sda1 ext3 9.7G 5.9G 3.4G 64% /
#/dev/sdb1 ext3 79G 73G 2.2G 98% /data
#variables
ssh=/usr/bin/ssh
sh_dir=/root/sh/
crondir=${sh_dir}crontab
source ${sh_dir}CONFIG
hosts="$LINUX_WEB_HOSTS"
user=`id -u`
let df_limit=80
#main
#主循环遍历机器
for HOST in $hosts ;do
flag_disk_file=$crondir/log/"$HOST".disk
log=$crondir/log/disk_error.log
#执行ssh 命令
capacity=`$ssh -o ConnectTimeout=2 root@$HOST "df" | grep "/dev/" | sed 's/\%//' | awk '{print $5}'`
let flags=0
#没法链接的主机,跳过本次循环
test -z "$capacity" && continue
#判断ssh命令返回结果
for used in $capacity ;do
if [ $used -ge $df_limit ];then
let flags=1
break
fi
done
#若是磁盘超过限制,则发送报警邮件
if [ "$flags" -eq 1 -a ! -f "$flag_disk_file" ];then
#sms
#for mobile in "$MOBILES";do
#echo "$HOST disk will full" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#done
for mail in $MAILS;do
echo "$HOST disk will full" | mail -s "$HOST disk will full" $mail
done
#log
date +'%F %T' >>$log
echo "$HOST disk will full" >> $log
#flag
echo "disk_error" >$flag_disk_file
fi
#若是磁盘正常,则发邮件解除报警邮件
if [ "$flags" -eq 0 -a -f "$flag_disk_file" ];then
#sms
#for mobile in "$MOBILES";do
#echo "$HOST disk ok"|/usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode
#done
for mail in $MAILS;do
echo "$HOST disk ok" | mail -s "$HOST disk ok" $mail
done
#log
date +'%F %T' >>$log
echo "$HOST disk ok" >> $log
#flag
rm -f $flag_disk_file
fi
done
#
结束更多请: linux 系统运维 37275208 vmware 虚拟化 166682360