| View previous topic :: View next topic |
| Author |
Message |
timeBandit Administrator


Joined: 31 Dec 2004 Posts: 2667 Location: here, there or in transit
|
Posted: Fri Feb 27, 2009 12:27 am Post subject: TIP: 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
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 |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1211 Location: U.S.A.
|
Posted: Fri Feb 27, 2009 8:58 am Post subject: |
|
|
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 |
|
 |
YourNameInHere n00b

Joined: 28 Mar 2007 Posts: 4
|
Posted: Fri Feb 27, 2009 10:19 am Post subject: |
|
|
what sms gateway do you use? Is there something for free to use?
thx
YourNameInHere |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1211 Location: U.S.A.
|
Posted: Fri Feb 27, 2009 10:47 am Post subject: |
|
|
| my cell phone provider has a gateway |
|
| Back to top |
|
 |
timeBandit Administrator


Joined: 31 Dec 2004 Posts: 2667 Location: here, there or in transit
|
Posted: Fri Feb 27, 2009 5:16 pm Post subject: |
|
|
| 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 |
|
 |
comprookie2000 Developer


Joined: 25 Jul 2004 Posts: 804 Location: Ft.Lauderdale Florida
|
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1211 Location: U.S.A.
|
Posted: Fri Mar 13, 2009 11:55 pm Post subject: |
|
|
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 |
|
 |
milomak Apprentice

Joined: 10 Apr 2008 Posts: 255
|
Posted: Mon Mar 16, 2009 5:34 pm Post subject: |
|
|
| 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 |
|
 |
.yankee Apprentice


Joined: 24 Feb 2008 Posts: 192 Location: Polska
|
Posted: Mon Mar 23, 2009 12:18 am Post subject: |
|
|
| Nice trick... But isn't it easier to use --keep-going emerge parameter? |
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1211 Location: U.S.A.
|
Posted: Mon Mar 23, 2009 12:24 am Post subject: |
|
|
| .yankee wrote: | | Nice trick... But isn't it easier to use --keep-going emerge parameter? |
Yeah. Or you could just use Ubuntu.  |
|
| Back to top |
|
 |
coolsnowmen Veteran


Joined: 30 Jun 2004 Posts: 1479 Location: No.VA
|
Posted: Mon Mar 23, 2009 5:41 pm Post subject: |
|
|
| BoneKracker wrote: | | .yankee wrote: | | Nice trick... But isn't it easier to use --keep-going emerge parameter? |
Yeah. Or you could just use Ubuntu.  |
You do know you are on forums.gentoo.org right? _________________ emerge: there are no ebuilds to satisfy "moo" |
|
| Back to top |
|
 |
timeBandit Administrator


Joined: 31 Dec 2004 Posts: 2667 Location: here, there or in transit
|
Posted: Mon Mar 23, 2009 5:45 pm Post subject: |
|
|
| .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 |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1211 Location: U.S.A.
|
Posted: Mon Mar 23, 2009 6:59 pm Post subject: |
|
|
| 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.  |
You do know you are on forums.gentoo.org right? |
You do know that was joke, right? |
|
| Back to top |
|
 |
polovinamozga n00b

Joined: 11 Sep 2008 Posts: 13
|
Posted: Wed Mar 25, 2009 4:48 am Post subject: |
|
|
| great script! |
|
| Back to top |
|
 |
.yankee Apprentice


Joined: 24 Feb 2008 Posts: 192 Location: Polska
|
Posted: Sun Mar 29, 2009 1:59 pm Post subject: |
|
|
| 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 |
|
 |
timeBandit Administrator


Joined: 31 Dec 2004 Posts: 2667 Location: here, there or in transit
|
Posted: Wed Apr 08, 2009 2:21 pm Post subject: |
|
|
| .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 ). 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 |
|
 |
BonezTheGoon Bodhisattva


Joined: 14 Jun 2002 Posts: 1374 Location: Albuquerque, NM -- birthplace of Microsoft and Gentoo
|
Posted: Tue Feb 16, 2010 4:46 pm Post subject: |
|
|
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 |
|
 |
bobspencer123 Guru


Joined: 19 Dec 2005 Posts: 541
|
Posted: Tue Feb 16, 2010 4:55 pm Post subject: |
|
|
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 |
|
 |
lazy_bum l33t


Joined: 16 Feb 2005 Posts: 658
|
Posted: Wed Feb 17, 2010 10:04 pm Post subject: |
|
|
| 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 |
|
 |
timeBandit Administrator


Joined: 31 Dec 2004 Posts: 2667 Location: here, there or in transit
|
Posted: Thu Feb 25, 2010 2:19 pm Post subject: |
|
|
| BonezTheGoon wrote: | | Awesome work! Thanks so much for sharing!! | 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. 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 |
|
 |
|