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 => @password)
cmd = "finduser #{user}" #<= 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 #<= 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 #<= The server the user is logged in on server_name: