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