-------------------------------checkdiskspace.sh-------------------------------------
ADMIN="admin@mydomain.com"
# set alert-level 90 % standard
ALERT=90
df -P | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $6 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge $ALERT ]; then
echo "space low on \"$partition ($usep%)\", on server $(hostname) at $(date)" |
mail -s "Alert: Free space low, $usep % used on $partition" $ADMIN
fi
done
---------------------------------End script---------------------------------------------
2. สร้าง crontab ให้สคริปทำงาน ทุกตี 4 ของทุกวัน
-------------------------Crontab------------------------
0 4 * * * sh /root/script/checkdiskspace.sh
อ้างอิง