Friday, 22 January 2010

Remote control using Twitter

I have been thinking about running task on a Ubuntu Linux machine remotely using Twitter. Why you ask, due to firewall restriction where the machine is located I can't get direct access to it but it has connection out to the internet.

So I thought I could send coded messages to it using Twitter and have it run certain tasks. Should be fairly easy to do in Python I thought, but what do use it for? Kicking off test runs, downloads or other system tasks?

Downloads seemed a simple place to start, why max out my home broadband usage limit when I can get the remote machine to download things off-peak.

For the proof of concept I decided to code it for using WGET and a command line YouTube down loader.

Using this Python Twitter API I was able to get a proto-type running in a short time.

Basically it should work like this,

  • I send a direct message to a Twitter account which only follows me and I follow on my main account.
  • This contains the code for type of download and the URL of the download.
  • The Python script is started by cron at scheduled times.
  • The script connects to Twitter and checks for direct messages.
  • It parses the direct message and either spawns a WGET or youTube-dl command to get the resource.
  • If its a video it then runs a command is run to convert it to divX ready for upload it to my phone.
  • If its a file then it is virus checked.
  • Finally the direct messages are deleted from the Twitter account and a reply sent to my Twitter account.
So now without physical or remote access to the machine I can queue up downloads to retrieve during off peak hours.

Now I've got it work, need to fine tune it to run other remote tasks, like restarting Weblogic or deploying new version of the application and running test suites.

1 comments:

adrian said...

that's fantastic Al, love it!