Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@telent
Created February 10, 2011 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telent/820990 to your computer and use it in GitHub Desktop.
Save telent/820990 to your computer and use it in GitHub Desktop.
display gnome notification-area thing whenever rsync is running
#!/bin/bash
function in_progress() {
notify-send "Backup running" "The backup is running. Please don't unplug Fred";
};
#PID=/tmp/hello/rsnapshot-running
#POLL=10
GROUP=users # could make this plugdev or staff or whoever
POLL=120
PID=/var/run/rsnapshot.pid
if ! ( id -a | grep -q $GROUP ) ; then
echo "Not a member of the $GROUP group, exiting" >&2
exit 0
fi
if [ x$DISPLAY = x ] ; then
echo "DISPLAY unset, exiting" >&2
fi
while xset q >/dev/null ; do
until test -f $PID ; do inotifywait `dirname $PID` 2>/dev/null ;done
xset q >/dev/null || exit 0
in_progress
while test -f $PID ;do
if zenity --notification --text "Backup in progress" --window-icon=/usr/share/icons/gnome/48x48/actions/document-save.png --timeout $POLL ;then
# zenity returns true if the icon is clicked, show a message.
test -f $PID && in_progress
fi
done
notify-send -t 10000 "Backup finished" "The backup has finished. It is safe to unplug Fred now"
done
@telent
Copy link
Author

telent commented Feb 10, 2011

Requires inotify-tools

The xset q calls are probably not as necessary as I thought they were when I added them, but are supposed to make the script die when DISPLAY goes away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment