Attention Seeking Behavior
Since perl 5.14, Perl has shipped with HTTP::Tiny and JSON:PP which allows accessing a large collection of web services without installing any additional modules trivial. I have a set of scripts that can be put on any server on the Internet with a modern Perl installed that can send me notifications.
Distractions are....oooh, shiny!
Ever get bored waiting for a script to complete on a remote server? Happens to me all the time. Then next thing I know I realize I've been reading the Perl Weekly for half an hour and the remote command completed twenty five minutes ago.
What I need is some way to notify me that we're done now. In my ideal world, I'd have a script that I could call like this
bash$ perl something_really_long.pl; notify "done with really long task"
How could I go about writing that?
Drop me an email
The simplest solution would be to send me an email, with a command that looks like:
bash$ perl something_really_long.pl; emailnotify "done with really long task"
Traditionally we'd do this by initializing a SMTP connection from the notifying machine itself; This is impractical these days for several reasons including modern SPAM filtering not trusting connections from random servers, and, of course, talking SMTP is non-trivial without several non-core modules from the CPAN.
Luckily in our modern cloud like infrastructure email-as-a-service is a real thing. Several providers allow you to request an email send with nothing more than a HTTP request. One such provider is Mandrill, who currently offer a large number of free emails on their trial account.
Cut me some Slack
Okay, I admit it. I never check my email in a timely fashion these days. If I dropped everything to check my email each time a new message arrived, I'd spend my entire day being interrupted by the latest breaking Buffy The Vampire Slayer news from London.pm rather than getting work done.
Anyway, all the cool kids are moving onto next generation communication systems like Slack. Often described as "Modern IRC", Slack is a web chat system that can also run in desktop clients and on mobile devices. Slack has a range of notification systems built in, from using modern HTML5 browser notifications into sending push notifications to the iOS devices that pretty much never leaves my side.
By leveraging this notification system o ntop of a free account I can send messages to my cell phone.
Last ditch: all going to POTS
Sometimes I'm away from my computer (shocking I know) and my cell phone is plugged in upstairs charging. What could we do to notify me in this situation? As a last ditch I guess we could call my house landline phone and hope that whoever answers it can track me down.
Twillo offers a service where it can phone you up and use text-to-speech to read you your message. A free trial account will be able to call the number that you verified the account from (with a disclaimer played before your message is read to remind you that this is just a trial account.)
Installing the utilities on the remote server.
Now I have these handy notification tools, how do I ship the scripts to the boxes I want to use them on? Ideally I'd use some sort of version control system like git, but not all the boxes have that installed. They all do have Perl however, so how can we leverage that to do our installation in pain free way?
First I need to run some code locally to package up my scripts into one single installer script:
The output of this script itself is a Perl script, one that I can store on a secret gist from gist.github.com, and access again using the raw URL link from anywhere that is connected to the Internet.
So, on any server I want to install my commands on now I can issue a simple curl command to download and immediately execute the Perl script from its secret location.
bash$ curl https://gist.githubusercontent.com/2shortplanks/<redacted>/gistfile1.txt | perl
The downloaded Perl script reconstitutes the original scripts that were found on my local machine on the remote server that's executing the command.
So, now computers all over the Internet can reach me day or night. If you'll excuse me, I'm just off to shop online for some earplugs...