Created
September 4, 2011 15:11
-
-
Save enkrates/1192990 to your computer and use it in GitHub Desktop.
A quick script to automatically choose the UTCS 32-bit server with the lowest current load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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' | |
doc = Nokogiri::HTML(open('http://apps.cs.utexas.edu/unixlabstatus/')) | |
lines = doc.css('td.ruptime') | |
machines = Array.new | |
i = 6 | |
while i+4 <= lines.length | |
if lines[i].content == "Public Linux Workstations - 64-bit" | |
i = i + 6000 | |
end | |
if lines[i+1].content == "up" | |
this_machine_name = lines[i].content | |
this_machine_load = lines[i+4].content | |
this_machine_data = Array[this_machine_name, this_machine_load] | |
machines << this_machine_data | |
end | |
i = i+5 | |
end | |
machines = machines.sort_by { |e| e[1] } | |
puts machines[0][0] + " has a load of " + machines[0][1] | |
exec "ssh " + machines[0][0] + ".cs.utexas.edu" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment