It's been something of a reoccurring dream of mine to
control my server remotely from my cellphone. Sure,
I could grab an SSH application and do it the right
way, but I decided it would be a bit more fun to send
direct messages to the server via Twitter.
Without pretense about the value of doing so,
here is a quick overview of how you too can
control your servers remotely via Twitter.
users is the list of users who are allowed to
perform a given command, pattern is the format
the direct message must take (at the moment this is
a literal match, but it would be pretty quick to
fire it up to match via regular expressions),
and rewrite is the command executed when
The final step is to setup a cronjob to periodically
run the script. Twitter historically doesn't deal well
with overly frequent polling, so I'd recommend setting
up the script to poll two or three times an hour.
Each time a command is executed by the script it
will record the username, input text and output command
Finally you just need to start direct messaging
commands to the listening account.
d my_account reboot apache
And, whenever your cronjob runs next, your commands
will be executed.
There are two usecases where I'm actually using this.
Both could be better done with different technology
(like, ya know, email), but I enjoyed taking a slightly
The first is updating sites and rebooting Apache from
my cellphone without actually needing to SSH into the
box (authentication is by public key only, not password),
and the second is allowing friends to update projects
hosted on my server (usually by pulling from a Git
repository and running a build script) without needing
to setup an account and public keys for them.
Like I mentioned above, I certainly think that using
email would be a superior approach to depending on
Twitter, and I certainly consider it to be a novelty