Skip to content

Commit

Permalink
Add status
Browse files Browse the repository at this point in the history
  • Loading branch information
map7 committed Oct 4, 2011
1 parent adbaf8b commit 64263d1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tc-control
Expand Up @@ -9,26 +9,39 @@ hash = JSON.parse(file)
def up?(ip)
result = `ping -c 1 #{ip}`
if $?.exitstatus == 0
puts
true
else
puts "Already down"
false
end
end

case ARGV[0]
when "shutdown"
hash["clients"].each {|client|
print "Shutdown #{client['name']}..."
puts "Shutdown #{client['name']}..."
`ssh root@#{client['ip']} 'shutdown -P now'` if up?(client['ip'])
}
when "startup"
hash["clients"].each {|client|
puts "Startup #{client['name']}..."
`wakeonlan #{client['mac']}`
}
when "status"
puts "Check status of each client"
hash["clients"].each {|client|
print "#{client['name']} is "

if up?(client['ip'])
puts "up"
else
puts "down"
end
}
else
puts "Usage: ./tc-control <startup/shutdown>"
puts "Usage: ./tc-control command
\nCommands
startup\tStart thin clients in clients.json
shutdown\tShutdown clients in clients.json
status\tCheck if clients are up or down."
end

0 comments on commit 64263d1

Please sign in to comment.