A tweeting simulation server!

designallYou can call this the “Poor man’s server” or even better the “Grad student’s server”.

Problem: I run codes remotely on my laptop at home from campus. I have an ubuntu Linux installed on it. I used to get my server to email me whenever it was done crunching the numbers. But now my server twitts it’s status! I had one more problem, my server is not connected to the internet via LAN and I share a wifi with my roommate (Berkeley is expensive I can’t afford to rent the whole apartment). Therefore, the IP address for my server gets changed occasionally (for example, if our wireless router gets reset) so my server twits it’s IP address every 10 minutes and this way I know to which IP, I need to connect. You can easily change the setting on your twitter account to send you updates on your cellphone in case you are running an important simulation

Solution:

your IP can be found by the following command in a Linux terminal

ifconfig | awk '{print $2}' | head -2 | tail -1 | sed 's/addr://'
output: 192.168.1.102 (Note: local IP)

We now store it in a variable

MyIP=`ifconfig | awk '{print $2}' | head -2 | tail -1 | sed 's/addr://'`
echo $MyIP

output: 192.168.1.102

We can now tweet this IP

curl -u username:password -d status=$MyIP  https://twitter.com/statuses/update.xml
If you don’t have curl you can install it by

sudo apt-get install curl

for example:

root@desktop:~$ curl -u username:password -d status="I am a linux script and my IP is "$MyIP  https://twitter.com/statuses/update.xml

will post the following on your twitter account

The output of the curl script

The output of the curl script

To run this scrip every 10 minutes simply make a CRON job and add this script to it. It comes in very handy when you run simulations everyday.

Advertisements

~ by marksalen on September 7, 2009.

2 Responses to “A tweeting simulation server!”

  1. Great! I’ve been wondering how to automate tweets from shell scripts. Combine this with any window that has been active for more than 10 minutes (pulled, for instance, from TOP) and we can automate the process of tweeting our current activity: surfing the web, writing code, or reading papers.

    • I agree, I had a little script that could get the 1st top job.
      I guess it was something like this

      PNAME=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk ‘{print $3 }’`

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: