3 # Reboot a machine connected to a Servertech Sentry power strip
5 # Copyright 2008 Google Inc., Ryan Kubiak <rkubiak@google.com>
6 # Released under the GPL v2
10 if {[llength $argv] < 3} {
11 puts stderr "Usage: $P <ts host> <ts port> <outlet>"
17 set tshost [lindex $argv 0]
18 set tsport [lindex $argv 1]
19 set outlet [lindex $argv 2]
23 while {$connected == 0 && $attempts < 10} {
24 spawn telnet $tshost $tsport
28 set attempts [ expr $attempts +1 ]
31 "Connection closed by foreign host." {
32 puts "Retrying attempt $attempts"
33 set rand [expr round(rand() * 15 + 6)]
34 puts "Waiting $rand before next attempt"
40 send "reboot $outlet\r"
41 expect "Command successful"
43 puts "Machine successfully rebooted."
53 send "reboot $outlet\r"
54 expect "Command successful"
56 puts "Machine successfully rebooted."
60 puts "Timed out connecting."
65 puts "Unable to connect after 10 connection attempts."