Gentoo Forums
Gentoo Forums
Quick Search: in
TIP: Send SMS alerts when emerge completes
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
timeBandit
Administrator
Administrator


Joined: 31 Dec 2004
Posts: 2667
Location: here, there or in transit

PostPosted: Fri Feb 27, 2009 12:27 am    Post subject: TIP: Send SMS alerts when emerge completes Reply with quote

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
SMS_ADDR="2015551212@sms.some-mobile.com"

LAST_PKG="$(tac /var/log/emerge.log | awk '$2 == ">>>" {print $4,$5,$6,$7; exit;}')"
CFG_MODS="$(find /etc -iname '._cfg????_*' | wc -l)"

mail -s"Emerge Completed" $SMS_ADDR <<-EOM
   ${RESULT} ${LAST_PKG}
   :::
   ${CFG_MODS} config updates pending
   $*
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.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1211
Location: U.S.A.

PostPosted: Fri Feb 27, 2009 8:58 am    Post subject: Reply with quote

Very nice. Thank you for sharing it.

I had thought about dropping a .forward file with my sms address during emerges, but even with "email_summary", it's far too much data. This captures the important tidbits.
Back to top
View user's profile Send private message
YourNameInHere
n00b
n00b


Joined: 28 Mar 2007
Posts: 4

PostPosted: Fri Feb 27, 2009 10:19 am    Post subject: Reply with quote

what sms gateway do you use? Is there something for free to use?

thx

YourNameInHere
Back to top
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1211
Location: U.S.A.

PostPosted: Fri Feb 27, 2009 10:47 am    Post subject: Reply with quote

my cell phone provider has a gateway
Back to top
View user's profile Send private message
timeBandit
Administrator
Administrator


Joined: 31 Dec 2004
Posts: 2667
Location: here, there or in transit

PostPosted: Fri Feb 27, 2009 5:16 pm    Post subject: Reply with quote

BoneKracker wrote:
my cell phone provider has a gateway
Likewise.

For US Verizon Wireless numbers the gateway address is number@vtext.com for text, number@vzwpix.com for multimedia messages. I think most carriers provide a similar service (in the US at least). Check the support section of the carrier's website or call customer service.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
comprookie2000
Developer
Developer


Joined: 25 Jul 2004
Posts: 804
Location: Ft.Lauderdale Florida

PostPosted: Fri Mar 13, 2009 11:32 pm    Post subject: Reply with quote

Thanks works great!
I found my cell phone providers number here;
http://en.wikipedia.org/wiki/SMS_gateway#Carrier-provided_SMS_to_email_gateways
_________________
http://dev.gentoo.org/~dabbott/
Back to top
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1211
Location: U.S.A.

PostPosted: Fri Mar 13, 2009 11:55 pm    Post subject: Reply with quote

comprookie2000 wrote:
Thanks works great!
I found my cell phone providers number here;
http://en.wikipedia.org/wiki/SMS_gateway#Carrier-provided_SMS_to_email_gateways

You might want to only send a few until you get a bill, so you can make sure they're not charging you (or see how much they're charging you).
Back to top
View user's profile Send private message
milomak
Apprentice
Apprentice


Joined: 10 Apr 2008
Posts: 255

PostPosted: Mon Mar 16, 2009 5:34 pm    Post subject: Reply with quote

This is very interesting the same has happened to me very time so I will be interested to see if I can implement it.
Back to top
View user's profile Send private message
.yankee
Apprentice
Apprentice


Joined: 24 Feb 2008
Posts: 192
Location: Polska

PostPosted: Mon Mar 23, 2009 12:18 am    Post subject: Reply with quote

Nice trick... But isn't it easier to use --keep-going emerge parameter?
Back to top
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1211
Location: U.S.A.

PostPosted: Mon Mar 23, 2009 12:24 am    Post subject: Reply with quote

.yankee wrote:
Nice trick... But isn't it easier to use --keep-going emerge parameter?

Yeah. Or you could just use Ubuntu. :P
Back to top
View user's profile Send private message
coolsnowmen
Veteran
Veteran


Joined: 30 Jun 2004
Posts: 1479
Location: No.VA

PostPosted: Mon Mar 23, 2009 5:41 pm    Post subject: Reply with quote

BoneKracker wrote:
.yankee wrote:
Nice trick... But isn't it easier to use --keep-going emerge parameter?

Yeah. Or you could just use Ubuntu. :P

You do know you are on forums.gentoo.org right?
_________________
emerge: there are no ebuilds to satisfy "moo"
Back to top
View user's profile Send private message
timeBandit
Administrator
Administrator


Joined: 31 Dec 2004
Posts: 2667
Location: here, there or in transit

PostPosted: Mon Mar 23, 2009 5:45 pm    Post subject: Reply with quote

.yankee wrote:
Nice trick... But isn't it easier to use --keep-going emerge parameter?
The two are not mutually exclusive.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1211
Location: U.S.A.

PostPosted: Mon Mar 23, 2009 6:59 pm    Post subject: Reply with quote

coolsnowmen wrote:
BoneKracker wrote:
.yankee wrote:
Nice trick... But isn't it easier to use --keep-going emerge parameter?

Yeah. Or you could just use Ubuntu. :P

You do know you are on forums.gentoo.org right?

You do know that was joke, right?
Back to top
View user's profile Send private message
polovinamozga
n00b
n00b


Joined: 11 Sep 2008
Posts: 13

PostPosted: Wed Mar 25, 2009 4:48 am    Post subject: Reply with quote

great script!
Back to top
View user's profile Send private message
.yankee
Apprentice
Apprentice


Joined: 24 Feb 2008
Posts: 192
Location: Polska

PostPosted: Sun Mar 29, 2009 1:59 pm    Post subject: Reply with quote

timeBandit wrote:
.yankee wrote:
Nice trick... But isn't it easier to use --keep-going emerge parameter?
The two are not mutually exclusive.


True... Though, if I understand the script well, it seems that the informative value of running it after emerge -keep-going would be very small. Did you think about modifying it so that it would parse the log more thoroughly? I guess it wouldn't be that difficult to detect, how many packages were skipped during such emerge job.
Back to top
View user's profile Send private message
timeBandit
Administrator
Administrator


Joined: 31 Dec 2004
Posts: 2667
Location: here, there or in transit

PostPosted: Wed Apr 08, 2009 2:21 pm    Post subject: Reply with quote

.yankee wrote:
True... Though, if I understand the script well, it seems that the informative value of running it after emerge -keep-going would be very small. Did you think about modifying it so that it would parse the log more thoroughly? I guess it wouldn't be that difficult to detect, how many packages were skipped during such emerge job.
Agreed, but I have no need. I am not too fond of --keep-going, I prefer to fix problems as they arise (as you might have guessed :wink:). When I have some time I'll look into counting failed packages. I have an idea for a simple solution but need to experiment.

Thanks for all the compliments and comments so far. :)
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
BonezTheGoon
Bodhisattva
Bodhisattva


Joined: 14 Jun 2002
Posts: 1374
Location: Albuquerque, NM -- birthplace of Microsoft and Gentoo

PostPosted: Tue Feb 16, 2010 4:46 pm    Post subject: Reply with quote

This is one of the coolest things I have ever seen someone contribute! I really would like to see this suggested as a feature update to portage so that you can just define an address in your /etc/make.conf and have it done every time without remembering to run the script. Have you submitted it as a feature request? I'd certainly vote for it's injection!!

Awesome work! Thanks so much for sharing!!
_________________
Vista needs more memory than Windows for Supercomputers
Back to top
View user's profile Send private message
bobspencer123
Guru
Guru


Joined: 19 Dec 2005
Posts: 541

PostPosted: Tue Feb 16, 2010 4:55 pm    Post subject: Reply with quote

Hey this looks like a great little script. Thanks so much for your effort.

I was wondering if this could be edited to include the ability to send an email about a package failure. I do have a cell phone but I'm a cheap sob and don't have unlimited text.
_________________
Increasingly becoming a 2 channel audio nut!
Back to top
View user's profile Send private message
lazy_bum
l33t
l33t


Joined: 16 Feb 2005
Posts: 658

PostPosted: Wed Feb 17, 2010 10:04 pm    Post subject: Reply with quote

bobspencer123 wrote:
Hey this looks like a great little script. Thanks so much for your effort.

I was wondering if this could be edited to include the ability to send an email about a package failure. I do have a cell phone but I'm a cheap sob and don't have unlimited text.

Sure you can. I've made some quick and ugly (and it is *ugly*) hack some days ago to send also latest logfile path (this could be edited to send ie. tail -100 failed.log).
Code:
#!/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
SMS_ADDR="your@mail"

LAST_PKG="$(tac /var/log/emerge.log | awk '$2 == ">>>" {print $4,$5,$6,$7; exit;}')"
CFG_MODS="$(find /etc -iname '._cfg????_*' | wc -l)"
LOG_PKG="$(ls -l -rt /var/log/portage/ | grep -v elog | tail -1 | awk '{print $9}')"

mail -s"Emerge Completed" $SMS_ADDR <<-EOM
   ${RESULT} ${LAST_PKG}
   :::
   see latest logfile /var/log/portage/${LOG_PKG}
   $*
EOM

_________________
roslin uberlay | grubelek
Back to top
View user's profile Send private message
timeBandit
Administrator
Administrator


Joined: 31 Dec 2004
Posts: 2667
Location: here, there or in transit

PostPosted: Thu Feb 25, 2010 2:19 pm    Post subject: Reply with quote

BonezTheGoon wrote:
Awesome work! Thanks so much for sharing!!
:D Thanks! Sorry for not responding sooner, this thread fell off my egosearch due to age.

bobspencer123 wrote:
I was wondering if this could be edited to include the ability to send an email...
Er...that's what it does. :wink: Conversion to SMS happens at the carrier's gateway address, not in the script. Just change SMS_ADDR to the email address where you want to send the note.

Note: The script is partially broken as of Portage 2.1.6.13 and later (at least in the 2.1.x series). The exit status of emerge no longer reflects the pass/fail status of the last ebuild. As a result the message sent reports PASS even if an ebuild failed. The log excerpt will still clue you in if there was a failure (e.g., "(5 of 17) app-who/badwolf").

I'll look into it soon and either find a more reliable test or file a bug on Portage (if warranted).
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum