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
How to enable Large Pages for a specific user on AIX?
Viewed 2869 times since Thu, Nov 29, 2018
AIX TCP connection status
Viewed 17284 times since Mon, Jul 29, 2019
Altering LVM Configuration When a Disk is Not in ODM Anymore
Viewed 3359 times since Mon, Jun 3, 2019
How to Backup and Upgrade a Virtual I/O Server Part I
Viewed 4848 times since Wed, Jun 5, 2019
AIX WIKIS developerworks
Viewed 2538 times since Sun, Jun 17, 2018
AIX: How to set automatic logoff (only for terminals)
Viewed 3289 times since Mon, Jun 11, 2018
AIX - How to get Memory infomation
Viewed 11343 times since Fri, Jun 8, 2018
7 Tips – Tuning Command Line History in Bash
Viewed 5601 times since Fri, Jul 5, 2019
AIX -- extending Logical Volumes online
Viewed 2943 times since Tue, Mar 12, 2019
Managing System Dump Devices sysdumpdev
Viewed 3792 times since Mon, Jul 9, 2018