Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9295927
  • 博文数量: 1669
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12594
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1669)

文章存档

2023年(4)

2022年(1)

2021年(10)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: 系统运维

2013-11-27 16:50:37

shell监控脚本-监控磁盘
2013-03-27 13:28:52
标签:linux shell 脚本 监控 监控磁盘
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dngood.blog.51cto.com/446195/1163558
shell监控脚本-监控磁盘


注意:请先参考 shell监控脚本-准备工作,监控脚本在 rhel5 下测试正常,其它版本的linux 系统请自行测试
#监控磁盘
cat chk_df.sh 
#!/bin/bash 

#script_name:chk_df.sh 
#check disk 

#last update 20130320 by dongnan 
#bbs#
#blog# http://dngood.blog.51cto.com 

#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 
        #mail 
        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 
        #mail 
        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
本文出自 “dongnan” 博客,请务必保留此出处http://dngood.blog.51cto.com/446195/1163558
阅读(675) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~