Ad Hoc Command-Line Notifications with Twitter
Posted: November 14th, 2009 | Author: Jerod | Filed under: Ruby, Tools | Tags: twitter | View CommentsHave you ever spent way too much time babysitting a long-running command? Code compilation, large file transfers, software upgrades and other time consuming tasks can trash productivity by requiring intermittent attention.
I have a novel idea; let’s not do that anymore!
There are undoubtedly dozens of solutions for this little problem, but I chose Ruby + Twitter for a few reasons:
- I like Ruby
- I like Twitter
- I want hassle-free SMS
- I want portability (small client-side configuration)
So, with those things in mind, here is what I’ve come up with:
1) A Special Twitter Account
Create a new account for your notifications. You’ll most likely want to protect its tweets unless you don’t mind just about anybody seeing all the notifications you’re sending to yourself. Once the account is set up, follow it from your main Twitter account and enable SMS notifications for its tweets.

2) A dead simple Ruby script
I’ve written about John Nunemaker’s Twitter gem a couple of times, and it once again makes its way into the toolbelt. Install if you don’t have it:
jerod@mbp:~$ sudo gem install twitter
This gem makes the notification script just a few lines of code:
You can name the script anything you like. I call it twitter_notify. Make it executable and ensure it is in your shell’s execution path (I symlink it so I can keep my code organized):
jerod@mbp:~$ chmod +x src/ruby/twitter/twitter_notify.rb jerod@mbp:~$ ln -s ~/src/ruby/twitter/twitter_notify.rb /usr/local/bin/twitter_notify
3) A Call to Notify
Anytime you want to be notified that a command has completed, just follow it with the twitter_notify command. There are a couple of ways to do this, and they are slightly different:
jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else && twitter_notify "all done copying!"
Or:
jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else; twitter_notify "command complete!"
Using && will only call the second command if the first command completed successfully. Using ; will call the second command regardless of how the first command completed. Adjust usage depending on your circumstance.
4) A Deserved Break
Now that you’ve set up your tools to handle the grunt work, walk away from the computer! Go outside, watch a movie, hang with your fam, who cares! When that task is complete you’ll get an SMS and you can deal with it then.
That’s all I got.
This is killer! Love the concept! As usual your posts are TOTALLY helpful! Oh, and btw, the proxy worked out great!
What advantages do you see Twitter+SMS having versus email?
With email, I can setup filters to organize the alerts nicely. Additionally, with a phone like the iPhone or an Android-based phone, I can get notifications when I get new emails.
Glad you like it Doug!
Also, glad the local proxy suggestion helped you out. I've gotten a lot of mileage out of Paros in my days. In fact, I'm considering writing my own native OS X proxy app in MacRuby for my next side project. If I ever get around to it…
Hi Vishal-
Good question. I've used email notifications for a long time (I still do for certain things) and I've found email to be more work to configure on all the different boxes I'm administering (ISPs blocking SMTP, firewalls, getting flagged as spam, etc). With this technique all you need is Ruby and the Twitter gem and you're good to go.
Also, I get a lot of email and I prefer not to push it to my phone. This is simply personal preference, but I've decided that when I'm away from the computer I'd rather check my email than have it check me.
Finally, I believe this method “scales” a little better since you can add interesting parties in a single location by having them follow the Twitter account. With email notifications you'd have to add their email address to each individual script that you've deployed to machines.
Didn't think about it in terms of scaling to add interested parties. Great point! This implies, then, that if you want different sets of people following different notifications, you need to setup unique twitter accounts for each notification type.
Yes, so it scales better in one way and worse in another way
For more complex scenarios I use Nagios which can notify via many different methods. In fact, Nagios is very easy to integrate with Twitter as well.
Social comments and analytics for this post…
This post was mentioned on Twitter by FollowMeTools: Please RT: Ad Hoc Command-Line Notifications with Twitter | blogt0sk1: Send SMS notifications to your.. http://bit.ly/31Gz2i...
This is killer! Love the concept! As usual your posts are TOTALLY helpful! Oh, and btw, the proxy worked out great!
What advantages do you see Twitter+SMS having versus email?
With email, I can setup filters to organize the alerts nicely. Additionally, with a phone like the iPhone or an Android-based phone, I can get notifications when I get new emails.
Glad you like it Doug!
Also, glad the local proxy suggestion helped you out. I've gotten a lot of mileage out of Paros in my days. In fact, I'm considering writing my own native OS X proxy app in MacRuby for my next side project. If I ever get around to it…
Hi Vishal-
Good question. I've used email notifications for a long time (I still do for certain things) and I've found email to be more work to configure on all the different boxes I'm administering (ISPs blocking SMTP, firewalls, getting flagged as spam, etc). With this technique all you need is Ruby and the Twitter gem and you're good to go.
Also, I get a lot of email and I prefer not to push it to my phone. This is simply personal preference, but I've decided that when I'm away from the computer I'd rather check my email than have it check me.
Finally, I believe this method “scales” a little better since you can add interesting parties in a single location by having them follow the Twitter account. With email notifications you'd have to add their email address to each individual script that you've deployed to machines.
Didn't think about it in terms of scaling to add interested parties. Great point! This implies, then, that if you want different sets of people following different notifications, you need to setup unique twitter accounts for each notification type.
Yes, so it scales better in one way and worse in another way
For more complex scenarios I use Nagios which can notify via many different methods. In fact, Nagios is very easy to integrate with Twitter as well.
thread! I’m not agree you standpoint,but toally approve your view!Anybody has his own dream,someone makes them reality , air jordan 9 another leaves it just dreams.So it lie on how hard you distribute,how long you persist! This post make a way to lead to success,ugg boots for saleany only insist on studying new knowledge and digest them for your own that can make you gradually growing up , Nike Air Force 1 Lowthank you for this outline,it will be very useful for those who are in the lost! ugg boots for sale