Debian Codegraph @

drivers/reboot-lantronix

raw
1 #!/usr/bin/expect
2 #
3 # Reboot a machine connected to a Lantronix SLC8
4 #
5 # Copyright 2008 Google Inc., Scott Zawalski <[email protected]>
6 # Released under the GPL v2
7
8 set P "reboot-lantronix"
9
10 if {[llength $argv] < 3} {
11 puts stderr "Usage: $P <ts host> <ts port> <outlet>"
12 exit 1
13 }
14
15 #Max number of attempts before stopping
16 set max_attempts {5}
17 set tshost [lindex $argv 0]
18 set tsport [lindex $argv 1]
19 set outlet [lindex $argv 2]
20 set connected {0}
21 set attempts {0}
22
23 while {$connected == 0 && $attempts < $max_attempts} {
24 spawn telnet $tshost $tsport
25 sleep 5
26 send "\r"
27 set timeout 15
28 set attempts [expr $attempts +1 ]
29 expect {
30 #Connection closed
31 "Connection closed by foreign host." {
32 puts "Retrying attempt $attempts"
33 }
34 #Already logged in
35 "RPC-22>" {
36 send "Reboot $outlet\r"
37 expect "Reboot Outlet $outlet"
38 send "Y\r"
39 expect "Rebooting"
40 expect "RPC-22"
41 send "quit\r"
42 puts "Machine successfully rebooted."
43 exit 0
44 }
45 timeout {
46 puts "Timed out connecting."
47 }
48 }
49 }
50
51 puts "Unable to connect after $attempts connection attempts."
52 exit 1