Lightening my school load

In the CS department at UT, we have lots of servers we can log into to do our work. Each machine’s load is listed on a public website, so we can make sure we log into a machine with some capacity to spare. The routine is check the page, pick a machine, and ssh into it.

Checking a webpage when what I want to do is ssh into a server is kind of a bummer, so I wrote up a quick ruby script to grab that status page, nokogiri it up, sort the 32-bit servers, and then send me on my way. I assume that at some point the script will stop working and I’ll have to do a better job, but in the meantime I’ll enjoy not touching a browser when I do my school work.

#! /usr/bin/env ruby

# This script is pretty fragile in that it will break 
# if the UTCS lab status page changes its HTML in a 
# fairly small way. So far, it works great.

# It requires nokogiri (gem install nokogiri).

# I have my user name set automatically with my 
# ssh-config file, so it doesn't figure into the 
# ssh command below. Later, I might either add 
# some code for a -X flag with ssh, or maybe just 
# switch to that overall.

require 'rubygems'
require 'nokogiri'
require 'open-uri'

lab_url = ''
doc = Nokogiri::HTML(open(lab_url))

lines = doc.css('td.ruptime')

machines =

i = 6

lab_title = 'Public Linux Workstations - 64-bit'

while i+4 <= lines.length
 if lines[i].content == lab_title
 i = i + 6000
 if lines[i+1].content == "up"
 machine_name = lines[i].content
 machine_load = lines[i+4].content
 machine_data = Array[machine_name, machine_load]
 machines << machine_data
 i = i+5

machines = machines.sort_by { |e| e[1] }

puts machines[0][0] + ' load: ' + machines[0][1]

exec 'ssh ' + machines[0][0] + ''


Lightening my school load

Tell me about it...