blob: e7f986c170d4150703dbe130e2e3a37421e6e6c1 [file] [log] [blame]
apw3812c032006-12-07 21:01:14 +00001#!/usr/bin/expect -f
2#
3# reboot-netfinity -- reboot netfinity machines via their management port
4#
5# This expect script reboots a machine via a managemant port.
6# It only works with the Netfinity-style Service Processors.
7# They have a number-driven interface
8#
9# example machines: Netfinity 6000R, 8500R
10# xSeries x350, x370
11#
12# usage:
13# reboot-netfinity <user> <password> <connect command> ...
14#
15# examples:
16# reboot-netfinity USERID PASSW0RD telnet 1.2.3.4 7033
17#
18# (C) Copyright IBM Corp. 2004, 2005, 2006
19# Author: Dave Hansen <haveblue@us.ibm.com>
20#
21# The Console Multiplexor is released under the GNU Public License V2
22#
23set P "reboot-netfinity"
24
25if {[llength $argv] < 2} {
26 puts stderr "Usage: $P <userid> <password> <cmd> ..."
27 exit 1
28}
29set argc [llength $argv]
30set userid [lindex $argv 0]
31set password [lindex $argv 1]
32set timeout 30
33set send_slow {1 .1}
34
35set command [lrange $argv 2 end]
36
37puts "$P: Logging into service processor with command \"$command\" to restart it";
38
39eval spawn [lrange $argv 2 end]
40
41send -s -- "\033\033\033\033\033"
42expect *;
43send "\033"
44
45expect {
46 #Log in
47 "USER ID:" {
48 send -s -- "$userid\r"
49 expect -exact "PASSWORD:"
50 send -s -- "$password\r"
51 exp_continue;
52 }
53 #Some machines use different login prompts
54 "User_id:" {
55 send -s -- "$userid\r"
56 expect -exact "Password:"
57 send -s -- "$password\r"
58 exp_continue;
59 }
60 #already logged in
61 "Z - Start Remote Video" {
62 send "6"
63 expect -exact "4 - Power On"
64 send "3"
65 expect -exact "2 - Power Off Immediately"
66 send "2"
67 expect -exact "0 - Write"
68 send "0"
69 expect -exact "6.3.2: Write"
70
71 send -s -- "\033\033\033\033\033"
72 expect -exact "Z - Start Remote Video"
73 send "6"
74 expect -exact "4 - Power On"
75 send "4"
76 expect -exact "2 - Power On Release CPU's Reset"
77 send "2"
78 expect -exact "0 - Write"
79 send "0"
80 expect -exact "6.4.2: Write"
81
82 # On kernels with ACPI support, the above may send an ACPI
83 # event to the OS to perform a clean shutdown. If that happens
84 # we may not ever come back up. Add the reboot command below
85 # to finish the job.
86 send -s -- "\033\033\033\033\033"
87 expect -exact "Z - Start Remote Video"
88 send "7"
89 expect -exact "4 - Restart SP"
90 send "2"
91 expect -exact "0 - Write"
92 send "0"
93 expect -exact "7.2: Write"
94 }
95
96}
97
98puts "$P: reboot initiated"