Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Send remote reminders when local activity finishes UNIX

Both of these tricks stem from building software from source on an older machine and wanting to be somewhere else (like outside) while still knowing everything that happens and knowing exactly when the process is finished. Neither of these tricks are complex, nor are they exclusive to tcsh.

The first uses the pipe output redirection and /usr/bin/tee:

 process |& tee output_log
which redirects both the process and error output into output_log, as well as your display (usage of tee stolen from soob's comment in this hint).

The second trick I use to send a text message to my cell phone when the process exits: process && send_message will execute send_message only if process exits without error. Alternatively, process || send_message will execute send_message if there are errors with process. Combine the two like this:

 (process && good_news) || bad_news
to be alerted in either case with different messages. For building source, I combine both tricks as follows (all on one line):
 ( make |& tee make_log && make install |& tee install_log && echo
  "Install complete" | mail -s "good news" me@text.address ) || echo
  "something didn't work" | mail -s "bad news" me@text.address
mail depends on sendmail or postfix being functional, and can be replaced with some other form of notification, like an AppleScript using your favorite mail program. And, of course, the whole bit has to be executed as root or make install will likely fail.

Pay a visit to your local man pages for more neat shell tricks, or for ways to adapt these tricks to work with your favorite shell.

    •    
  • Currently 3.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[3,047 views]  

Send remote reminders when local activity finishes | 2 comments | Create New Account
Click here to return to the 'Send remote reminders when local activity finishes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Please include disclaimers on FRAGILE CODE
Authored by: merlyn on Jan 29, '04 01:20:25PM
Ugh.

(process && good_news) || bad_news
Please don't suggest junk like that without also giving the limitation that you must be very sure that good_news exits with a good status. Otherwise, you end up doing both good_news and bad_news.

I could wrangle the neck of the guy who first posted that to a usenet newsgroup many years ago thinking they were "clever" without thinking about how dangerous of a meme it was when not annotated with the proper caveat. Especially when other forms work even better.

[ Reply to This | # ]

Please include disclaimers on FRAGILE CODE
Authored by: name99 on Jan 30, '04 04:42:17AM

Ah, the UNIX mindset in action.
(1) Tell the world how great the shell is because of redirection etc.
(2) Learn that there are various cases where these tools are problematic.
(3) (And this is the key one, the one that really exposes the pleasant side of the UNIX personality) --- spend the rest of your life shouting at people who actually try to use the tools you evangelized in (1) without doing a thing to either
(a) FIX the damn problems so that they cannot be made by novices or even
(b) explaining to the poor user what they did wrong, why, and how to avoid the error in future.

Truly a thing of wonder to see an individual be so clueless on the most elementary social interaction level.



[ Reply to This | # ]