EnterpriseSCHEDULE 7.3

Job Commands Using “Expect” the scripting tool

Contents Job Commands using “Expect” ...... 2 General guide lines ...... 3 Using Expect’s record feature to capture an interactive session ..... 4 Common edit changes made to Autoexpect recorded scripts ...... 7 Breaking Expect Jobs into reusable pieces using include within a Job ...... 11 Creating Expect prototype Job Templates ...... 14 Appendix A – Additional Centricity/IDX Notes ...... 16

1

Job Commands using “Expect” Job Commands using “Expect” is a powerful feature of EnterpriseSCHEDULE. Jobs can invoke several types of scripts. “Expect” is one of those powerful options on a Job’s “submit” property page. In this article we will explore how to create scripts, record menu sessions into scripts, and additional methods for expanding your job tool kit.

The features that will be discussed are:

• Overview of “Expect” the scripting tool

• Using Expect’s Record feature to capture an interactive session into a Job

• Modifying the commands of a Expect Recorded session to parameterize menu responses

• Common modification made to Expect Recorded sessions

• Breaking Expect Jobs into reusable pieces using include within a Job

• Creating Expect prototype Job Templates

Expect is a -based Toolkit that is readily available on and Linux as freeware. There are also kits for Windows and OpenVMS but we will focus on the most common platforms utilizing Expect which are Unix and Linux. There are several free install kits typically RPMs available for Expect. Please refer to ISE’s FAQs for a list of ftp sites containing install kits.

Expect can be used as a freeform Scripting language or as a tool to record interactive terminal sessions which can then to be reused as a script. This article will focus on recording and modifying Expect recorded sessions are then imported into an ISE EnterpriseSCHEDULE Job. An excellent Expect reference guide is “Exploring Expect” by Don Libes an O’Reilly publication.

2

General guide lines When creating an EnterpriseSCHEDULE Job select the “Submit” property page and set the “Command shell” to Expect. Then import the Expect Script into the Commands area of the Job.

3 Using Expect’s record feature to capture an interactive session Once Expect is installed, from a terminal session you can immediately begin creating your scripts without any formal scripting knowledge by entering the command “autoexpect –p”. Every key stroke you enter will be entered into a local text file called “script.exp” until “exit” is typed. After you terminate the autoexpect session you will have a script in “script.exp” that is able to replay the session. You can use this to record common tasks and/or capture character cell menu sessions. Furthermore you can import the newly created script into a Schedule Job with command “schedule insert {jobname} script.exp”.

Simple example:

autoexpect -p

schedule insert myexpectjob script.exp

4 ISE Windows Gui Client

5 Here is an example of a GE Centricity/IDX menu session that was recorded with autoexpect:

6 Common edit changes made to Autoexpect recorded scripts Once a script is recorded and imported into EnterpriseSCHEDULE it is common to make edit changes. The scripts generated are a combination of paired lines that begin with “send “ and “expect “ whereby “send” is the what Expect feeds to the recorded program and “expect” is the output generated from the recorded program.

A “send “ response can be changed into Job parameters and/or Schedule variables including date variables. The dynamic token substitution can be added to the autoexpect session, for example:

You could use a Job parameter such as parameter 1

send -- "((P1))\r"

You could use a Schedule variable

Send – “((endofmonth))\r"

where endofmonth is a variable in the same directory as the job.

For previewing the outcome that the commands will be after dynamic token substitution of variables and parameters

Schedule preprocess {jobname}

If ‘P1’ was ‘Hello world’, then “preprocess” would return

send – “Hello world\r”

7 What to remove from the “expect” line?

Many times capturing a menu traversal like GE Centricity/IDX, the non-human readable characters can and should be removed to make the lines more readable and keep the size of the commands lines less than 255. Lines can be re-duce down to as a few characters as you like. Typically, it’s best to leave at least one character so the timing can be managed if needed. Also, it’s helpful to keep human readable information. Watch out for menu inserted dates that appear in the “expect” lines because these will change daily. You need to remove these dates because they will never be the same day to day. In the example below “##” is the pre-edited version. expect "Terminal" send -- "-VT220\r" expect "Override this specification? NO=> " send -- "\r" expect "Select Function: " send -- "30\r" expect "Select Activity:" send -- "1\r" expect "Device:" send -- "\r" expect "Right Margin:" send -- "\r" expect "Advanced Options?:" send -- "Y" expect "Device:" send -- "/db/per/Claims/lov10hBluetmp.nop\r" ## Parameters: \"RWSN\" => " expect "=> " send -- "\r" expect "Form:" send -- "1298\r" ##Is this the one Y=> expect "=>" send -- "Y\r" expect "Begin new run?" send -- "Y\r" ##Do you want the formatter? NO=> expect "NO=>" send -- "\r" ## Do you want to queue this activity? No=> expect "No=>" send -- "\r" expect "Select Activity: " send -- "\r" expect "Select Function: "

8 send -- "\r" expect "PER>" send -- "h\r" expect eof

By default autoexpect adds lines at the beginning of the script that add control to the script. One of those controls is the delay in between lines. This delay is very helpful in driving menu session such that the response “send” doesn’t occur too quickly. Another control allows you to force a breakout of the script if the menu session hangs on a “send” or “expect”.

9 Many times a menu transversal is a sequence of “down arrows” until you reach a particular menu choice. You can remove the repeated “expect” “send” pairs with a “while” loop. This becomes handy if your menu selections are changed by the development staff. When using a “while” loop the menu selection will continue to work even as additional menu selections are added and removed.

10 Breaking Expect Jobs into reusable pieces using include within a Job When you build your Expect Jobs you will find that many of pieces are repeated. Sometimes it is handy to break these pieces into separate jobs and then use the ((include jobname)) directive to build the pieces back up

a) In the example below, job /Cedars/Protoi_claims_x has a Job include /cedars/include_idx_login.

b) In the example below that, job /cedars/include_idx_login has a Job include /cedars/include_env and a variable substitution /cedars/database

c) The last screen shot is the “Preview” of all the pieces put together. In addition, notice the parameter and variable substitution at the top of Job.

11

12

13

Creating Expect prototype Job Templates Now that you have captured some jobs and made them generic such they could easy be copied as additional jobs with a different set of parameters you may want to make the Job(s) a prototype template(s). Simply, rename a job to proto_{jobname} and they will become part of the lookup tree for templates.

Please refer to ISE templates documentation for more details.

14

15 Appendix A – Additional Centricity/IDX Notes When driving a Centricity/IDX menu session it is important to keep the menu session in sequential mode so that you can replay the session as a batch Job. In particular you want to force the session to not use the pop-up screens that can occur because this will break the sequential running when an additional session is spawned off. The following may need to be modified.

Inside of IDX/Centricity account management you can define a user to be a Batch User account. In general there are two types of accounts, a DBMS account that skips the Centricity security (AES programmer level sometimes called the back door) that is many times already setup as a Batch user. But typically you will need to run many of your menu sessions with standard Centricity user account in which case you will need to manage the terminal type.

Make sure the terminal type is simple type. There is an IDX/Centricity Unix terminal symbol that can be set. You want the symbol to be set to a very primitive terminal type, like a line printer so that character cell displays are used by IDX.

Additionally, inside of a cache/IDX/Centricity session you can set the terminal type. Typically, you want to set the terminal type early in the session.

Examples: spawn /usr/bin/cache -U PER match_max 100000 expect "PER" send -- "DO EP1^BAR\r" expect "DO EP1^BAR\r" send -- "\r" expect "Terminal" send -- "C-VT220\r"

send -- "cache\r" expect -exact "%SYS>" send -- "d ^%XX\r" expect -exact "Change to: %SYS=> " send -- "PHS\r" expect -exact "PHS>" send -- "d ^ZIDTRM\r" spawn /usr/bin/cache -U PER match_max 100000 expect "PER" send -- "DO ^UDX\r"

16 expect "DO ^UDX\r" send -- "\r" expect "Terminal" send -- "C-VT220\r"

17