Logging the load balance I created a load balancing server at work and have to keep track of which server it adds the user to, so I wrote a little Ruby script that will do just that.

I'm looking for any critique of my work, can I do anything better at all.

Source(user information, directory information, and server information changed for security):

#!/local/usr/bin/ruby

require 'net/ssh'

@username = 'user'
@password =  nil
@host     = 'server_to_run_command_on'

def loadbalance_server_data(user)
  check = Net::SSH.start(@host, @username, :password =&gt; @password)
  cmd = "finduser #{user}" #&lt;= Custom command that finds user info
  res = check.exec!(cmd)
  data = res
  write_data(data)
end

def write_data(data)
  File.open("path/to/log.txt", "a+"){ |s| s.puts(data) }
end

user_list = %w(user user user).each do |user|
  loadbalance_server_data(user)
end


Example of log:


Querying: servers..

Server usage report for user
        server_name:  
        server_name:  
        server_name:  
        server_name:  
        server_name:  
        server_name:  
        server_name:  dbus-daemon gvfsd thunderbird #&lt;= These programs always run on this server no matter what server they are logged in on
        server_name:  
        server_name:  
        server_name:  dbus-daemon dbus-launch do_4000_clone_u execrulz gam_server gnome-screensav gnome-settings- gnome-vfs-daemo newphp openbox openbox-session qccm soffice soffice.bin tint2 umessage #&lt;= The server the user is logged in on
        server_name:
Constants in UPPERCASE

@username = 'user'
@password =  nil
@host     = 'server_to_run_command_on'


should be constants, as well as:

LOGFILE = "path/to/log.txt"


Marking a variable as constant in Ruby just needs upper-casing its name.

Return value simplification

res = check.exec!(cmd)
data = res
write_data(data)


Is unnecessarily long just write:

write_data( check.exec!(cmd) )




Other then this minor remarks, the code looks as straightforward and readable as it can get.