Get desktop notification for filesystem usage

Here is a little un-intrusive script that will alert you whenever your filesystem is going above a certain percentage threshold.
This was tested under opensuse 12.3, but should really work on any linux running KDE (or at least having the kdialog binary installed).

You can save it under your user’s bin directory, for example /home/fblaise/bin/alert_fs.sh in my case.

[sourcecode language=’bash’]
#!/bin/bash

# Fred Blaise
# Cron this script in order to receive passive alerts about filesystem getting full.
# Set PCT_THRESHOLD to your liking

export DISPLAY=:0

PCT_THRESHOLD=80
ALERT_TITLE=”WARNING: Filesystem almost full”

(
df -h |grep ^/dev |awk {‘print $1,$5,$6′} |
while read devfs pctused mntpoint; do
pctnum=${pctused%%}
if [[ “${pctnum}” -ge “${PCT_THRESHOLD}” ]]; then
kdialog –title “${ALERT_TITLE}” –passivepopup “${devfs} mounted on ${mntpoint} is at ${pctused}.”
fi
done
)
[/sourcecode]

Don’t forget to make this shell script executable.

We could then imagine a crontab looking like this, for checking every 10 minutes:

[sourcecode language=’bash’]-*/10 * * * * fblaise /home/fblaise/bin/alert_fs.sh[/sourcecode]

Whenever one of your filesystem crosses the threshold, a passive box will be displayed. I have my bar on the right side of the screen, and the result is the following:

fs_kdialog

It is a very basic script. One could add support for choosing what FS types should be monitored, how often to receive notifications. If you do make this better, please share!