Send remote reminders when local activity finishes

Jan 29, '04 09:36:00AM

Contributed by: kfaulhaber

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.

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040121013303553