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 routing - How Do I Compare ODM with the Current Routing Table?
Viewed 2591 times since Mon, Jul 29, 2019
Working with Virtual media library on VIO servers
Viewed 15135 times since Thu, Feb 21, 2019
Burn Image to DVD in AIX
Viewed 13436 times since Thu, Sep 20, 2018
Monitor logfiles and command output on AIX using multitail.
Viewed 2281 times since Thu, Feb 21, 2019
Configuration of AIX Fast Connect and SMBFS
Viewed 8419 times since Mon, Jun 18, 2018
AIX, System Admin↑ The chrctcp command
Viewed 3026 times since Fri, Apr 19, 2019
AIX 6.1: Extend VG 0516-1714 extendvg 0516-1254 extendvg
Viewed 4470 times since Fri, Jul 6, 2018
Tips I Picked up at the Power Systems Technical University
Viewed 2770 times since Mon, Jun 11, 2018
View mksysb content & restore individual files
Viewed 1825 times since Tue, Jul 17, 2018
AIX Increase paging space logical volume size
Viewed 2871 times since Tue, Jul 17, 2018