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
IVM and VLAN Tagging
Viewed 10646 times since Mon, May 28, 2018
System Admin Mirrorvg without locking the volume group
Viewed 3324 times since Mon, May 21, 2018
n a perfect world....rootvg would always reside on hdisk0
Viewed 2491 times since Thu, Jun 6, 2019
Customizing a NIM Client Restore With a Post-Install Script
Viewed 11239 times since Wed, May 30, 2018
Software management in AIX
Viewed 7080 times since Mon, Jun 25, 2018
AIX oslevel version OS
Viewed 5177 times since Wed, Apr 17, 2019
Processes and Devices—It’s All About the Children
Viewed 2438 times since Wed, May 30, 2018
AIX: How to set automatic logoff (only for terminals)
Viewed 3328 times since Mon, Jun 11, 2018
replacing (hot-swap) failed disk in rootvg
Viewed 9436 times since Thu, Sep 20, 2018
Oslevel shows wrong AIX’s level. Why
Viewed 4992 times since Thu, Feb 21, 2019