blob: 9b5082db21f1b56973b2579548b1e27ce77ee0d1 [file] [log] [blame]
apw3812c032006-12-07 21:01:14 +00001#!/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 <haveblue@us.ibm.com>
15#
16# The Console Multiplexor is released under the GNU Public License V2
17#
18set P "reboot-rsa"
19
20if {[llength $argv] < 3} {
21 puts stderr "Usage: $P <username> <password> <cmd> ..."
22 exit 1
23}
24set username [lindex $argv 0]
25set password [lindex $argv 1]
26
27log_user 0
28#stty echo
29#log_file -a "$logfile"
30
31proc note {m} {
32 global P
33 puts "$P: $m"
34}
35proc warn {m} {
36 global P
37 puts "$P: WARNING: $m"
38}
39proc winge {m} {
40 global P
41 puts "$P: ERROR: $m"
42}
43
44set elapsed_time 0
45set timeout 10
46
47set command [lrange $argv 2 end]
48eval spawn [lrange $argv 2 end]
49
50note "Logging into service processor with command \"$command\" to restart it";
51
52expect {
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
70expect {
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
79expect {
80 "Restart Server Immediately" {
81 note "Saw \"Server Power/Restart\" screen. Selecting \"Restart\"";
82 send "\t\t\t\t\t\r";
83 }
84}
85
86expect {
87 "Restarting the system immediately" {
88 note "Saw restart confirmation prompt, pressing enter";
89 send "\r"
90 }
91}
92
93expect {
94 "The system is performing a Restart Server Immediately" {
95 note "the system is restarting";
96 exit 0;
97 }
98}
99
100winge "an error occurred while restarting the server"
101exit 1;