HOWTO: POWER On using expect PDF Print E-mail
User Rating: / 4
PoorBest 
Written by Michael Felt   

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"

ote: you will need to change the PASSWORD to your system admin password.

Below is an example of the output. - And I expect this would work with Power6  and Power7, although the prompts and command option numbers may be a bit different.

michael@x054:[/home/michael]pwrOn 1
/opt/bin/pwrOn performs 'cu -l tty1
spawn cu -l tty1
Connected
login to Hypervisor


Welcome
Machine type-model: 9110-51A
Serial number: 0639B8D
Date: 2013-12-12
Time: 8:09:24
Service Processor: Primary
User ID: admin
Password: ********
Number of columns [80-255, Currently: 80]:
Number of lines [24-255, Currently: 24]:
System name: X100-p51A-054321D
Version: SF240_418
User: admin
Copyright © 2002-2012 IBM Corporation. All rights reserved.

 1. Power/Restart Control
 2. System Service Aids
 3. System Information
 4. System Configuration
 5. Network Services
 6. Performance Setup
 7. On Demand Utilities
 8. Concurrent Maintenance
 9. Login Profile
99. Log out








S1> 1

Power/Restart Control

 1. Power On/Off System
 2. Auto Power Restart
 3. Immediate Power Off
 4. System Reboot
 5. Wake On LAN
98. Return to previous menu
99. Log out














S1> 1

Power On/Off System
Current system power state: Off
Current firmware boot side: Temporary
Current system server firmware state: Not running

 1. System boot speed
        Currently: Fast
 2. Firmware boot side for the next boot
        Currently: Temporary
 3. System operating mode
        Currently: Normal
 4. AIX/Linux partition mode boot
        Currently: Continue to operating system
 5. Boot to system server firmware
        Currently: Running
 6. System power off policy
        Currently: Power off
 7. i5/OS partition mode boot
        Currently: A
 8. Power on
98. Return to previous menu
99. Log out

S1> 8

The system is powering on.
PRESS ENTER TO CONTINUE:
Power On/Off System
Current system power state: Off
Current firmware boot side: Temporary
Current system server firmware state: Unknown

 1. System boot speed
        Currently: Fast
 2. Firmware boot side for the next boot
        Currently: Temporary
 3. System operating mode
        Currently: Normal
 4. AIX/Linux partition mode boot
        Currently: Continue to operating system
 5. Boot to system server firmware
        Currently: Running
 6. System power off policy
        Currently: Power off
 7. i5/OS partition mode boot
        Currently: A
 8. Power on
98. Return to previous menu
99. Log out

S1> 99

You have logged out.
[x054]~.

Power On Successful

michael@x054:[/home/michael]

Script command is complete on Thu Dec 12 08:14:07 CUT 2013.

 
< Prev   Next >
Login