The following script alerts you when your root partition is almost full:
- Update the Server : - apt-get update
- Install mailx client :- apt-get install bsd-mailx
- Create a File disk.sh
- Add the Content
#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=9
if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
mail -s 'Disk Space Alert' ictops@gmail.com << EOF
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi
The script sends an email when the disk usage rises above the percentage specified by the THRESHOLD variable (9% here).
Script automatically run when it added into the Crontab file
root@ubuntu:~# crontab -e
10 15 * * * /root/disk.sh (Execute the command at 3.10 pm everyday)
No comments:
Post a Comment