|
HOWTO: POWER On using expect |
|
|
Using expect to automate mundane tasks
I have a Power5 system I use for testing, no HMC and I cannot always depend on being at a location where I can use the web-based ASMI interface. Plus, I have to wait for the web-interface to load. I prefer to use the serial line connection from tty1 to the serial port of the Power5. But typing in the commands got boring too. Enter expect, a program that can be told what to expect and then send an automated reply.
My program to automatically start a Power5 system
#!/usr/bin/expect -f
send_user "$argv0 performs 'cu -l tty[lrange $argv 0 0]\n"
spawn cu -l tty[lrange $argv 0 0]
expect {
" DEVICE LOCKED" { puts "*********locked\n"; close; exit }
"onnected" {
puts "login to Hypervisor\n";
send \n;
}
"ogin: " {
puts "**** already active\n exiting\n"; close; exit;
}
}
expect "User ID: " { send admin\n }
expect "assword: " { send PASSWORD\n }
expect " 80]: " { send \n }
expect {
" 24]: " { send \n }
" 25]: " { send \n }
}
expect "S1> " { send 1\n; sleep 1 }
expect "S1> " { send 1\n; sleep 1 }
expect "S1> " { send 8\n; sleep 1 }
expect "PRESS ENTER TO CONTINUE:" { send \n }
expect "S1> " { send 99\n; sleep 1 }
expect "out." { send "~." }
expect "~." { send "\n" }
puts "\n\nPower On Successful\n"Note: you will need to change the PASSWORD to your system admin password.
|