| 1 |
#!/usr/bin/expect |
| 2 |
# |
| 3 |
# reboot-rsa2 -- reboot systems via their RSA-II management cards |
| 4 |
# |
| 5 |
# Use a systems RSA (II) managment card to hard reset that system. |
| 6 |
# |
| 7 |
# usage: |
| 8 |
# reboot-rsa2 <userid> <password> <connect command> ... |
| 9 |
# |
| 10 |
# examples: |
| 11 |
# reboot-rsa2 FOO BAR telnet 1.2.3.4 23 |
| 12 |
# |
| 13 |
# (C) Copyright IBM Corp. 2004, 2005, 2006 |
| 14 |
# Author: Aileen Sheedy <[email protected]> |
| 15 |
# |
| 16 |
# The Console Multiplexor is released under the GNU Public License V2 |
| 17 |
# |
| 18 |
set P "reboot-rsa2" |
| 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 |
"username:" { |
| 62 |
send "$username\r$password\r" |
| 63 |
} |
| 64 |
timeout { |
| 65 |
winge "Never saw opening screen with \"username:\"" |
| 66 |
exit 2 |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
expect { |
| 71 |
"Invalid login!" { |
| 72 |
winge "Invalid username or password" |
| 73 |
exit 2 |
| 74 |
} |
| 75 |
">" { |
| 76 |
send "reset\r" |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
expect { |
| 81 |
"ok" { |
| 82 |
note "System restarting" |
| 83 |
send "exit\r" |
| 84 |
exit 0 |
| 85 |
} |
| 86 |
timeout { |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
winge "an error occurred while restarting the server" |
| 91 |
exit 1 |