#!/bin/bash
#取得每一個分區的使用百分比(不要百分號)
percent=`df -k | grep -v Filesystem| awk
'{print int($5)}'
`
查看每一個分區:
df -k | grep Filesystem
![](http://static.javashuo.com/static/loading.gif)
查看指定分區:
df -k | grep sda
![](http://static.javashuo.com/static/loading.gif)
#循環判斷分區使用率是否超過90%
for
each_one in $percent
do
#判斷使用率是否超過90%
if
[ $each_one -ge 90 ];then
#若是超過90 則把使用狀況發給mail_address mail_address換成你的郵件地址
df | mail -s
"Disk Critical"
mail_address
fi
done
把上面的內容保存到diskfree.sh 而後chmod +x diskfree.sh 好比你保存在/root目錄下 添加天天0點自動執行 vi /etc/crontab 追加以下一句 0 0 * * * root /root/diskfree.sh > /dev/null