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.

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
AIX How to Investigate a System Reboot
Viewed 6413 times since Tue, Aug 14, 2018
AIX - How to get Memory infomation
Viewed 9768 times since Fri, Jun 8, 2018
Install and configure GNU watch (gwatch) on AIX
Viewed 7709 times since Thu, Feb 21, 2019
How to clear/clean/erase/delete/reset network adapter configuration on AIX?
Viewed 12400 times since Thu, Nov 29, 2018
SNAP in AIX
Viewed 11439 times since Mon, Sep 17, 2018
Working with Virtual media library on VIO servers
Viewed 14963 times since Thu, Feb 21, 2019
Top 4 Reasons for Node Reboot or Node Eviction in Real Application Cluster (RAC) Environment
Viewed 87164 times since Thu, Jun 21, 2018
AIX HA / HACMP, System Admin↑ Mountguard
Viewed 6526 times since Mon, Jun 3, 2019
Removing Failed or Missing Paths
Viewed 2685 times since Wed, May 30, 2018
AIX Creating a Volume Group
Viewed 2436 times since Tue, Jul 17, 2018