Ubuntu: Script to Check Internet Connection and Repair

At school there are a set of laptops which I occasionally run experiments on for my research. I usually like to work remotely as I travel a bit and live in other cities. These laptops are all connected to the university network through a wireless AP in my office which passes the DHCP requests to somewhere in the department. This lets each one get an external IP which is extremely useful for SSH-ing into the machines one at a time remotely. However sometimes, for unknown reasons the IPs revert back to 10.x.x.x addresses and aren’t reachable. The problem can be solved by releasing the old address a couple of times:

sudo dhclient -r wlan1
sudo dhclient -r wlan1

and then asking for a new address:

sudo dhclient wlan1

However, this isn’t too helpful if I’m out of the lab. So to automate this I came up with this script which can be turned into a cronjob:

(more…)

Updated DNS Zone Update tool for Hostmonster

A couple years ago I posted a slightly modified script for hostmonster to update the dns zone entries for subdomains. It used mechanize and ruby. However, since then my script broke as hostmonster made some changes to their backend. Another guy made some changes that seemed to work for a while, but again it has broken. My previous post about this is here.

The culprit seems to be the mixture of javascript / ajax and the fact that hostmonster returns an empty page when you append the /ajax onto the dnszone url. No worries though, I found another way to do it.

Using Watir and Headless, it is possible to achieve the same functionality.

You need to add a few things to ubuntu to make it work:
sudo apt-get install ruby ruby-dev xvfb
sudo gem install watir
sudo gem install headless

Here’s the updated script (note, you can still use the same cron jobs and ip scripts etc. from the previous two techniques.:

#!/usr/bin/ruby
(more…)