Debian Codegraph @

drivers/reboot-newisys

raw
1 #!/usr/bin/expect -f
2 #
3 # reboot-newisys -- reboot a newisys system via its management interface
4 #
5 # This expect script reboots a newisys machine using its command
6 # interface. This is typically accessed over ssh.
7 #
8 # usage:
9 # reboot-newisys <user> <password> <connect command> ...
10 #
11 # examples:
12 # reboot-newisys USERID PASSW0RD ssh 1.2.3.4
13 #
14 # (C) Copyright IBM Corp. 2004, 2005, 2006
15 # Author: Daniel Sauble <[email protected]>
16 #
17 # The Console Multiplexor is released under the GNU Public License V2
18 #
19 set P "reboot-newisys"
20
21 if {[llength $argv] != 4} {
22 puts stderr "Usage: $P <userid> <password> <type> <machine>"
23 exit 1
24 }
25 set userid [lindex $argv 0]
26 set password [lindex $argv 1]
27 set machine [lindex $argv 3]
28 set timeout 30
29
30 puts "$P: connecting to $machine to initiate reboot ..."
31
32 # Log in
33 eval spawn "ssh -o StrictHostKeyChecking=no $userid\@$machine"
34 expect "password: "
35 send -- "$password\r"
36 expect "localhost \$ "
37 send "platform get power state\r"
38
39 # Check to see if the machine is on or off
40 # then restart it
41 expect {
42 "On" {send "platform set power state cycle -f\r"}
43 "Off" {send "platform set power state on -f\r"}
44 }
45 expect "localhost \$ "
46 expect "localhost \$ "
47 send "exit\r"
48
49 puts "$P: reboot initated"