linux shell脚本检测硬盘磁盘空间 邮件报警

原文:http://www.weiruoyu.cn/?p=368

使用shell脚本监控硬盘空间剩余空间 邮件报警

1.先观察一下磁盘,和如何使用脚本

 
 
  1. [root@localhost ~]# df -h

  2. 文件系统 容量 已用 可用 已用% 挂载点

  3. /dev/mapper/VolGroup00-LogVol00

  4. 8.9G 2.6G 5.9G 31% /

  5. /dev/sda1 99M 13M 82M 13% /boot

  6. tmpfs 188M 0 188M 0% /dev/shm

  7. [root@localhost ~]# df -h |sed -n '3p'|awk '{print $4}'|cut -f 1 -d '%'

  8. 31

2.脚本(超过70%报警)

 
 
  1. #!/bin/bash

  2. disk_sda1=`df -h |sed -n '3p'|awk '{print $4}'|cut -f 1 -d '%'`

  3. if

  4. ((disk_sda1 > 70));

  5. then

  6. echo `date` "192.168.56.128 this is over 70%" |mail -s "disk over 70%" [email protected],[email protected]

  7. fi

脚本备份(完整测试shell脚本)

 
 
  1. #!/bin/bash

  2. disk_sda1=`df -h |sed -n '3p'|awk '{print $4}'|cut -f 1 -d '%'`

  3. if

  4. ((disk_sda1 > 80));

  5. then

  6. echo "this is error"

  7. echo `date` "192.168.56.128 this is over 70%" |mail -s "disk over 70%" [email protected],[email protected]

  8. else

  9. echo "this is ok"

  10. fi

3.计划任务

 
 

更详细参考:http://www.weiruoyu.cn/?p=368


=============================

参考:

http://fdsazi.blog.51cto.com/1871366/419328

http://jason1110.blog.51cto.com/3924620/714827

http://huangrs.blog.51cto.com/2677571/788668

你可能感兴趣的:(linux,shell,脚本,硬盘,监控)