Notify me when emerge is done
As a Gentoo user, I frequently install new software or update existing packages using emerge. Unlike binary package managers, building packages from source using emerge takes time, and I prefer running it inside a detached screen session, because (a) if I close the session it continues in the background and (b) it actually runs faster when it doesn't need to show all the compilation output in an X terminal.
This has an annoying side effect: I sometimes start a long update process and forget I did it. If things fail (or even if they succeed) I don't know about it.
Today, I solved this problem using notify-send, the libnotify binary client. I've created a short shell script wrapper to emerge which sends me a notification once emerge finishes, along with the original command line arguments and exit status code (0 = ok, failure otherwise):
-
#!/bin/sh
-
-
ARGS=$@
-
-
/usr/bin/emerge "$ARGS"
-
STATUS=$?
-
if [ "$STATUS" = "0" ]
-
then
-
LEVEL="normal"
-
else
-
LEVEL="critical"
-
fi
-
-
/usr/bin/notify-send --expire-time=0 --urgency=$LEVEL "emerge finished" "Exit Code: $STATUS
-
Emerge args: $ARGS"
If you save this code in a file named emerge-notify (and of course remember to chmod +x this file) you could then do this (from a GNOME terminal or any other X terminal):
-
$ ./emerge-notify -puD world
And you'll get a nice notification when it's done:
Of course, you need libnotify the notify-send binary and dbus for this.
















This is great!
It would be nice to add a tail of the output to the mail if the LEVEL was critical. This is especially useful if you rebooted the machine since the operation was finished (Laptops mostly) and cannot connect to the screen anymore to see the error.