BMX Bicycle freestyle
BMX Bicycle freestyle

Wednesday, June 10, 2009

Low disk space notifications

linux low disk space notifications

Pre-requisite

In order for the pop-up message to appear, you would need to install “libnotify-bin”.

Code:
sudo apt-get install libnotify-bin


Script

The script will check the free disk space in “/dev/sda1″. It will show a pop-up message for 30 seconds when the free space is below 100MB. If the free space is below 50MB, it will show a pop-up message for 5 minutes. You should modify these parameters to your own requirement.

Copy and paste the script below to a file called “checklowdisk”.

Code:
#!/bin/sh

DISKSPACE=`df | grep "/dev/sda1" | awk '{ print $4 }'`

if [ "$DISKSPACE" -lt "51200" ] ; then
/usr/bin/notify-send -u critical -t 300000 \
'Check low disk' '/dev/sda1 is less than 50MB.'
exit
fi

if [ "$DISKSPACE" -lt "102400" ] ; then
/usr/bin/notify-send -u normal -t 30000 \
'Check low disk' '/dev/sda1 is less than 100MB.'
fi



Setting up the script

Make the script executable:

Code:
chmod +x checklowdisk


Change file ownership to root:

Code:
sudo chown root:root checklowdisk


Move file to “/usr/bin”:

Code:
sudo mv checklowdisk /usr/bin/


Set-up crontab

I chose to run the script hourly using crontab.

Edit crontab:

Code:
crontab -e


Add this line in the editor:

Code:
00 * * * * env DISPLAY=:0 /usr/bin/checklowdisk


Save and close the editor. The crontab is now configured, and the script will run at the hour.
thanx:Chewearn

to free up disk space more effectively click here

0 comments:

Post a Comment