For reasons which I am not going to explain here, the root partition of my eeePC (running Ubuntu Intrepid) has gone dangerously low on disk space. Usually, I have about 250MB to 300MB remaining in the partition. But twice now, the free disk space went below 50MB, and once almost at zero.
When the disk space was close to zero, I just happened to have Krusader opened. As a consequence of the low disk space, Krusader lost the custom settings I had, and reverted to default. It was time wasting to redo the customisation again and I think I was also lucky that nothing else went wrong.
So, I am sure there are a few things I could do to fix the low free space problem. But I think it would be useful to have a warning message when the free disk space dropped below a limit. Therefore, I wrote a script to do this.
The steps below is tested in an Ubuntu Intrepid Ibex platform. I am not sure if it works the same for other platform.
Pre-requisite
In order for the pop-up message to appear, you would need to install “libnotify-bin”.
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”.
#!/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:
chmod +x checklowdisk
Change file ownership to root:
sudo chown root:root checklowdisk
Move file to “/usr/bin”:
sudo mv checklowdisk /usr/bin/
Set-up crontab
I chose to run the script hourly using crontab.
Edit crontab:
crontab -e
Add this line in the editor:
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.

Comments 2
WOW! just what I needed for Linux Mint Felicia! THANKS A LOT!!!
Posted 04 Apr 2009 at 6:38 am ¶hi Jerther
Posted 09 Apr 2009 at 9:07 am ¶I’m glad the info was useful, thanks for your comment.
Post a Comment