| OLD | NEW |
| 1 #!/usr/bin/expect -- | 1 #!/usr/bin/expect -- |
| 2 # | 2 # |
| 3 # Reboot a machine connected to an APC power strip | 3 # Reboot a machine connected to an APC power strip |
| 4 # | 4 # |
| 5 # Copyright 2007 Google Inc., Martin J. Bligh <mbligh@google.com> | 5 # Copyright 2007 Google Inc., Martin J. Bligh <mbligh@google.com> |
| 6 set P "reboot-apc" | 6 set P "reboot-apc" |
| 7 | 7 |
| 8 # | 8 # |
| 9 # OPTIONS: options parser. | 9 # OPTIONS: options parser. |
| 10 # | 10 # |
| 11 proc shift {_list} { | 11 proc shift {_list} { |
| 12 upvar $_list list | 12 upvar $_list list |
| 13 set res [lindex $list 0] | 13 set res [lindex $list 0] |
| 14 set list [lreplace $list 0 0] | 14 set list [lreplace $list 0 0] |
| 15 return $res | 15 return $res |
| 16 } | 16 } |
| 17 | 17 |
| 18 proc arg {_list arg} { | 18 proc arg {_list arg} { |
| 19 upvar $_list list | 19 upvar $_list list |
| 20 if {[llength $list] < 1} { | 20 if {[llength $list] < 1} { |
| 21 puts stderr "$arg: required argument missing" | 21 puts stderr "$arg: required argument missing" |
| 22 exit 1 | 22 exit 1 |
| 23 } | 23 } |
| 24 return [shift list] | 24 return [shift list] |
| 25 } | 25 } |
| 26 | 26 |
| 27 proc enter_outlet {outlet} { |
| 28 send "\r" |
| 29 expect "> " |
| 30 send $outlet |
| 31 send "\r" |
| 32 } |
| 33 |
| 27 set timeout 10 | 34 set timeout 10 |
| 28 set user {apc} | 35 set user {apc} |
| 29 set pass {apc} | 36 set pass {apc} |
| 30 set host [lindex $argv 0] | 37 set host [lindex $argv 0] |
| 31 set outlet [lindex $argv 1] | 38 set outlet [lindex $argv 1] |
| 32 shift argv | 39 shift argv |
| 33 shift argv | 40 shift argv |
| 34 | 41 |
| 35 while {[llength $argv] > 0} { | 42 while {[llength $argv] > 0} { |
| 36 puts "length [llength $argv]" | 43 puts "length [llength $argv]" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 61 send "\r" | 68 send "\r" |
| 62 expect "1- Device Manager" | 69 expect "1- Device Manager" |
| 63 expect "> " | 70 expect "> " |
| 64 send "1\r" | 71 send "1\r" |
| 65 # We get a different prompt if we're just an outlet controller | 72 # We get a different prompt if we're just an outlet controller |
| 66 # decide which response we need to enter | 73 # decide which response we need to enter |
| 67 set timeout 2 | 74 set timeout 2 |
| 68 expect { | 75 expect { |
| 69 "3- Outlet Control/Configuration" { | 76 "3- Outlet Control/Configuration" { |
| 70 send "3\r" | 77 send "3\r" |
| 78 enter_outlet $outlet |
| 71 exp_continue | 79 exp_continue |
| 72 } | 80 } |
| 73 "2- Outlet Control" { | 81 "2- Outlet Control" { |
| 74 send "2\r" | 82 send "2\r" |
| 83 enter_outlet $outlet |
| 84 exp_continue |
| 85 } |
| 86 "2- Outlet Management" { |
| 87 send "2\r" |
| 75 exp_continue | 88 exp_continue |
| 76 } | 89 } |
| 77 } | 90 } |
| 78 send "\r" | |
| 79 expect "> " | |
| 80 send $outlet | |
| 81 send "\r" | |
| 82 # Here too, if we're just an outlet controller we don't get the option | 91 # Here too, if we're just an outlet controller we don't get the option |
| 83 # to modify configuration | 92 # to modify configuration |
| 84 expect { | 93 expect { |
| 85 "1- Control Outlet" { | 94 "1- Control Outlet" { |
| 86 send "1\r" | 95 send "1\r" |
| 87 } | 96 } |
| 97 "1- Outlet Control/Configuration" { |
| 98 send "1\r" |
| 99 enter_outlet $outlet |
| 100 } |
| 88 } | 101 } |
| 89 expect "3- Immediate Reboot" | 102 expect "3- Immediate Reboot" |
| 90 expect "> " | 103 expect "> " |
| 91 send "3\r" | 104 send "3\r" |
| 92 expect "Immediate Reboot" | 105 expect "Immediate Reboot" |
| 93 expect "Enter 'YES' to continue or <ENTER> to cancel :" | 106 expect "Enter 'YES' to continue or <ENTER> to cancel :" |
| 94 send "YES\r" | 107 send "YES\r" |
| 95 expect "Press <ENTER> to continue..." | 108 expect "Press <ENTER> to continue..." |
| OLD | NEW |