shell监控脚本-监控磁盘

简介:

shell监控脚本-监控磁盘

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

 
  1. cat chk_df.sh

  2. #!/bin/bash

  3. #

  4. #script_name:chk_df.sh

  5. #check disk

  6. #

  7. #last update 20130320 by dongnan

  8. #bbs# http://bbs.ywwd.net/

  9. #blog# http://dngood.blog.51cto.com

  10. #

  11. #df -Th

  12. #Filesystem    Type    Size  Used Avail Use% Mounted on

  13. #/dev/sda1     ext3    9.7G  5.9G  3.4G  64% /

  14. #/dev/sdb1     ext3     79G   73G  2.2G  98% /data

  15. #variables

  16. ssh=/usr/bin/ssh

  17. sh_dir=/root/sh/

  18. crondir=${sh_dir}crontab

  19. source ${sh_dir}CONFIG

  20. hosts="$LINUX_WEB_HOSTS"

  21. user=`id -u`

  22. let df_limit=80

  23. #main

  24. #主循环遍历机器

  25. for HOST in $hosts ;do

  26. flag_disk_file=$crondir/log/"$HOST".disk

  27. log=$crondir/log/disk_error.log

  28.    #执行ssh 命令

  29. capacity=`$ssh -o ConnectTimeout=2 root@$HOST "df" | grep "/dev/" | sed 's/\%//' | awk '{print $5}'`

  30.    let flags=0

  31.    #无法连接的主机,跳过本次循环

  32.    test -z "$capacity" && continue

  33.    #判断ssh命令返回结果

  34.    for used in $capacity ;do

  35.        if [ $used -ge $df_limit  ];then

  36.            let flags=1

  37.            break

  38.        fi

  39.    done

  40.   #如果磁盘超过限制,则发送报警邮件

  41.    if [ "$flags" -eq 1 -a ! -f "$flag_disk_file" ];then

  42.        #sms

  43.        #for mobile in "$MOBILES";do

  44.            #echo "$HOST disk will full" | /usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode

  45.        #done

  46.        #mail

  47.        for mail in $MAILS;do

  48.            echo "$HOST disk will full" | mail -s "$HOST disk will full" $mail

  49.        done

  50.        #log

  51.        date +'%F %T' >>$log

  52.        echo "$HOST disk will full" >> $log

  53.        #flag

  54.        echo "disk_error" >$flag_disk_file

  55.    fi

  56.    #如果磁盘正常,则发邮件解除报警邮件

  57.    if [ "$flags" -eq 0 -a  -f "$flag_disk_file" ];then

  58.        #sms

  59.        #for mobile in "$MOBILES";do

  60.            #echo "$HOST disk ok"|/usr/local/bin/gammu --sendsms TEXT "$mobile" -unicode

  61.        #done

  62.        #mail

  63.        for mail in $MAILS;do

  64.            echo "$HOST disk ok" | mail -s "$HOST disk ok" $mail

  65.        done

  66.        #log

  67.        date +'%F %T' >>$log

  68.        echo "$HOST disk ok" >> $log

  69.        #flag

  70.        rm -f $flag_disk_file

  71.    fi

  72. done


结束
更多请:  
linux 系统运维  37275208  
vmware 虚拟化  166682360


本文转自 dongnan 51CTO博客,原文链接:http://blog.51cto.com/dngood/1163558


相关文章
|
Web App开发 监控 关系型数据库
使用shell批量监控磁盘坏块(二)
之前分享了第一篇 使用shell批量监控磁盘坏块(一),今天来简单说说这个需求的实现内容 。 首先主要思路是通过中控的机器来发送监控的细节,然后返回结果。 首先就是我们需要有一个服务器列表,里面会有这些需要的元数据信息。
1266 0
|
Web App开发 监控 Shell
使用shell批量监控磁盘坏块(一)
硬件的监控其实还是蛮重要的,这个部分在嘉年华中也着重强调过,不过做起来确实还是有一些难度,我们也尝试了一些方法,最终准备两条腿走路,一边使用中控的方式来统一监控管理,同事考虑把硬件监控揉入zabbix的监控体系之中。
1086 0
|
18天前
|
弹性计算 Shell Perl
ecs服务器shell常用脚本练习(二)
【4月更文挑战第1天】shell代码训练(二)
102 1
|
20天前
|
Java Shell
SpringBoot启动脚本Shell
SpringBoot启动脚本Shell
15 0
|
2天前
|
Shell
Shell脚本之流程控制语句
Shell脚本之流程控制语句
|
3天前
|
JSON 运维 监控
训练shell常用脚本练习(三)
【4月更文挑战第14天】shell代码训练(三)
14 1
|
7天前
|
存储 弹性计算 Shell
ecs服务器shell常用脚本练习(十)
【4月更文挑战第11天】shell代码训练(十)
137 0
|
7天前
|
弹性计算 Shell Go
ecs服务器shell常用脚本练习(九)
【4月更文挑战第10天】shell代码训练(八)
124 0
|
17天前
|
Shell
【shell】实时查看网卡流量脚本
【shell】实时查看网卡流量脚本
|
23天前
|
Shell Linux C++
【Shell 编程设计】 编写自己的清理后台的Shell脚本
【Shell 编程设计】 编写自己的清理后台的Shell脚本
29 1