Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner

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