Using http://www.weiruoyu.cn/?p=368
Shell script monitors hard disk space remaining space email alerts
1. First look at the disk, and how to use the script
- [[email protected] ~]# df -h
- File System capacity used available used% mount point
- /dev/mapper /volgroup00-logvol00
- 8.9g 2.6g 5.9g 31% /
- /dev/sda1 99m 13m 82m 13% /boot
- tmpfs 188M  0  188M   0% /DEV/SHM
- [[EMAIL PROTECTED] ~]# DF -h |sed -n ' 3p ' |awk ' {print $4} ' |cut -f 1 -d '% '
- 31
2. Script (more than 70% alarms)
- #!/bin/bash
- disk_sda1=
df -h |sed -n ‘3p‘|awk ‘{print $4}‘|cut -f 1 -d ‘%‘
- If
- ((disk_sda1 > 70));
- Then
- echo
date
"192.168.56.128" 70% "|mail-s" Disk over 70% "[email protected],[email protected]
- Fi
Script Backup (full test shell script)
- #!/bin/bash
- disk_sda1=
df -h |sed -n ‘3p‘|awk ‘{print $4}‘|cut -f 1 -d ‘%‘
- If
- ((disk_sda1 > 80));
- Then
- echo "This is error"
- echo
date
"192.168.56.128" 70% "|mail-s" Disk over 70% "[email protected],[email protected]
- Else
- echo "This is OK"
- Fi
3. Scheduled Tasks
- [Email protected] tmp]# CRONTAB-E
Add to
3-hour Check
- * */3 * * */var/tmp/check_disk.sh
Or a 10-minute check.
- */10 * * * */var/tmp/check_disk.sh
=============================
Linux shell script detects hard disk space mail alerts