| 1 |
#!/usr/bin/expect |
| 2 |
# |
| 3 |
# reboot-rsa -- reboot systems with RSA management cards |
| 4 |
# |
| 5 |
# Reboot systems via their RSA (I) managment card interface. |
| 6 |
# |
| 7 |
# usage: |
| 8 |
# reboot-rsa <userid> <password> <connect commands> ... |
| 9 |
# |
| 10 |
# example |
| 11 |
# reboot-rsa FOO BAR telnet 1.2.3.4 |
| 12 |
# |
| 13 |
# (C) Copyright IBM Corp. 2004, 2005, 2006 |
| 14 |
# Author: Dave Hansen <[email protected]> |
| 15 |
# |
| 16 |
# The Console Multiplexor is released under the GNU Public License V2 |
| 17 |
# |
| 18 |
set P "reboot-rsa" |
| 19 |
|
| 20 |
if {[llength $argv] < 3} { |
| 21 |
puts stderr "Usage: $P <username> <password> <cmd> ..." |
| 22 |
exit 1 |
| 23 |
} |
| 24 |
set username [lindex $argv 0] |
| 25 |
set password [lindex $argv 1] |
| 26 |
|
| 27 |
log_user 0 |
| 28 |
#stty echo |
| 29 |
#log_file -a "$logfile" |
| 30 |
|
| 31 |
proc note {m} { |
| 32 |
global P |
| 33 |
puts "$P: $m" |
| 34 |
} |
| 35 |
proc warn {m} { |
| 36 |
global P |
| 37 |
puts "$P: WARNING: $m" |
| 38 |
} |
| 39 |
proc winge {m} { |
| 40 |
global P |
| 41 |
puts "$P: ERROR: $m" |
| 42 |
} |
| 43 |
|
| 44 |
set elapsed_time 0 |
| 45 |
set timeout 10 |
| 46 |
|
| 47 |
set command [lrange $argv 2 end] |
| 48 |
eval spawn [lrange $argv 2 end] |
| 49 |
|
| 50 |
note "Logging into service processor with command \"$command\" to restart it"; |
| 51 |
|
| 52 |
expect { |
| 53 |
"Connection closed by foreign host." { |
| 54 |
winge "Telnet connection closed." |
| 55 |
exit 1; |
| 56 |
} |
| 57 |
"Unable to connect to remote host:" { |
| 58 |
winge "Someone may already have the service processor"; |
| 59 |
exit 2; |
| 60 |
} |
| 61 |
"Login ID:" { |
| 62 |
send "$username\t$password\r" |
| 63 |
} |
| 64 |
timeout { |
| 65 |
winge "never saw opening screen with \"Login ID:\"" |
| 66 |
exit 2; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
expect { |
| 71 |
"Log Off" { |
| 72 |
send "\t\t\t\t\r" |
| 73 |
note "Saw opening screen, selecting \"Server Power/Restart\""; |
| 74 |
} |
| 75 |
timeout { |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
expect { |
| 80 |
"Restart Server Immediately" { |
| 81 |
note "Saw \"Server Power/Restart\" screen. Selecting \"Restart\""; |
| 82 |
send "\t\t\t\t\t\r"; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
expect { |
| 87 |
"Restarting the system immediately" { |
| 88 |
note "Saw restart confirmation prompt, pressing enter"; |
| 89 |
send "\r" |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
expect { |
| 94 |
"The system is performing a Restart Server Immediately" { |
| 95 |
note "the system is restarting"; |
| 96 |
exit 0; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
winge "an error occurred while restarting the server" |
| 101 |
exit 1; |