Gentoo Trick: Send SMS alerts when emerge completes
My most recent large update (>500 packages) prompted this idea. Around the tenth time an ebuild failed mere moments after I left the room (not to return for hours), I decided to have the darn thing alert me when it wanted attention.
The following assumes you have installed:
- The mailx client (mail-client/mailx), to send mail from shell scripts and the command line.
- An MTA (mail transfer agent) for mailx to use, such as Postfix, Sendmail or ssmtp.
This script is intended to run in a pipeline after emerge and send a short message to explain why emerge stopped.
| /usr/local/sbin/emobalert: |
| #!/bin/sh # Record exit status of emerge–must precede ALL other commands! [ $? -eq 0 ] && RESULT=”PASS” || RESULT=”FAIL” # Change next line to your mobile/SMS address LAST_PKG=”$(tac /var/log/emerge.log | awk ‘$2 == “>>>” {print $4,$5,$6,$7; exit;}’)” mail -s”Emerge Completed” $SMS_ADDR <<-EOM |
Change SMS_ADDR to your phone’s SMS address and be sure to mark the script executable. You might also want to make it readable only by root if you need to guard your mobile number.
Usage is simple:
| Example: |
| emerge -uDv world; emobalert |
That’s it. Notice you run the script unconditionally after emerge so it can detect the exit status (that is, use the semicolon, never && or || or any other pipe connector).
When emerge exits, you’ll receive a text message similar to this:
| Sample message: |
| From: root@localhost.localdomain (Emerge Completed) PASS (2 of 2) app-crypt/seahorse-2.22.3 ::: 0 config updates pending |
The message body reports the last ebuild attempted, whether the overall merge succeeded or failed and whether you need to apply any configuration file updates. Any command-line arguments supplied to emobalert are appended to the message.
On those rare occasions when you have better things to do than watch compiler output scroll by, this trick helps you still catch problems quickly.
related: http://en.wikipedia.org/wiki/SMS_gateway#Carrier-provided_SMS_to_email_gateways







