写一个脚本监控根分区磁盘大小超过60%时在当前shell中警告

#!/bin/bash
Disk_Warn()
{
        Disk_Use=`df -h | awk '/\/$/{print $5}'|sed 's/%//g'`
        TTY=`ps | awk '/bash$/{print $2}'`
        [ "$Disk_Use" -gt "60" ] &&{
                echo "Date: `date` Warning:Your / is full fix it now!!"
                sleep 2
                Disk_Warn
        }||{
                Disk_Warn
                sleep 2
        }
}
Disk_Warn

输出结果:

[root@localhost mnt]# sh Warn.sh 
Date: Sat Aug 25 09:33:57 EDT 2018 Warning:Your / is full fix it now!!
Date: Sat Aug 25 09:33:59 EDT 2018 Warning:Your / is full fix it now!!

 

你可能感兴趣的:(shell)