greater than

expect-lite


Automation for the rest of us

Installation and Quick Start Guide


Download

expect-lite can be downloaded from the expect-lite Project Page: http://sourceforge.net/projects/expect-lite
The tar.gz package includes expect-lite, as well as over 25 examples.

Quick Install

Untar the expect-lite package, and copy the expect-lite file in your path (typically ~/bin/).
cp expect-lite ~/bin/
Test by typing at the prompt:
expect-lite
If you see the help, then it is ready to go, installation is complete!

Quick Start

Expect-lite has many features which make it useful, and the documenation highlights those. But to start using expect-lite quickly, you require two items:
  1. a script
  2. a host 
Here is a quick script which you can paste into a file to test expect-lite, call it test.elt :
; ==== Ping localhost and report result ====
@5
>ping -c 2 localhost
+$packet_rx=([0-9]+) received
>
>echo "Packets received are:$packet_rx"
The second item you require is a host to run your script against. Expect-lite is designed to log into a remote host and run your script, as if a person was typing the commands. However that may require setting up ssh keys and so forth, and this is the Quick Start section. Type the following to run the above script on your localhost:
expect-lite -c test.elt -r none
There should be output that looks similar to the following:
cvmiller@maile:~/Freescale$ 
cvmiller@maile:~/Freescale$ ping -c 2 localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.053 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.056 ms

--- localhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.053/0.054/0.056/0.007 ms
cvmiller@maile:~/Freescale$
Assigned Var:packet_rx=2


cvmiller@maile:~/Freescale$ echo "Packets received:2"
Packets received:2

##Overall Result: PASS
Congratulations you have just run your first expect-lite script! To find out more details on tuning see More Details.

BSD-Style License

Copyright (C) Freescale Semiconductor, Inc. 2005-2007

See the  COPYING for information on usage and redistribution
of this file, and for a DISCLAIMER OF ALL WARRANTIES.

More Details

Expect-lite was created to prevent the scriptor, you, from having to write Expect scripts in TCL. However with that in mind, there are a few TCL details one should know that will tune expect-lite to perform best in your environment.

Since expect-lite is written in Expect/TCL, an interpretive language, making changes to the global variables controlling the behaviour does not require recompilation.

There are several global variables inside expect-lite which will help tune it to your environment. Open your favourite editor, and load expect-lite. The following sections will cover the tuneable variables:
Note:  As the above tunable items are migrated to expect-lite directives, this section will be deprecated.

Default Timeout

The nature of expect, is that something is sent, and something else is expected to return, expect-lite will wait until the timeout value for that something to return. If the required string is not returned in the defined time, expect-lite will declare the test failed, and return non zero.
set timeout 10

The default timeout is used to set a reasonable value for a timeout when the user script has not set a timeout. Once the user script has set a timeout (eg. @60), the default timeout will no longer be used.

Infinite loop protection

With the addition of looping support in expect-lite (version 3.0.0+), infinite loop protection has been implemented to prevent user scripts from looping forever.
set _el_infinite_loop 5000
Expect-lite detects an infinite loop by decrementing this value each time the script loops. Once this value is zero, expect-lite will print and Error, and fail the test. It is important to know that expect-lite does not detect multiple sequencial loops in the user script, and therefore the value of _el_infinite_loop should be able to accommodate all desired looping in the user script. Typically this will be between 5000 and 10000 depending on how much looping is performed in the user scripts.

User Name and Password

Expect-lite supports three connection methods:
  1. telnet
  2. ssh
  3. ssh_key
The user name and password will be used for connection methods 1 & 2. Clearly method 3 is more secure since the user name and passwords are not placed in expect-lite. However this may not be practical for your environment.
set user "root"
set pass "123456"
If the user name is not blank (eg. set user "") access method 3 will use that user name rather than the one of the current login when exchanging ssh_keys.

Connect Method

As mentioned above, expect-lite supports three methods to connect to remote hosts. The ssh_key method is the most secure, as no passwords are utilized. However this requires setting up ssh keys prior to using this method.
# connects to login host, and logs in as $USER
#
# Choose one login method here
#
#set connect_method "telnet"
#set connect_method "ssh"
set connect_method "ssh_key"
There is a forth method, as shown in the Quick Start, where no remote login is performed. This method was designed primarily for the Quick Start section, however, it can be used for most scripts (such as in the Cygwin environment). To invoke this method the value of "none" is given for the remote host on the command line.
expect-lite remote_host=none cmd_file=test.elt
Even when no remote host is required, it is best to log into the localhost, since the underlying Expect has problems with synchronization (between send and expect strings) when a remote host is not specified. The provided shell script 'setup_local_ssh.sh' (in the Tools directory) will setup the localhost with ssh keys. It is only necessary to run it once:
./Tools/setup_local_ssh.sh

Print Warnings

Expect-lite will always print Errors, and should fail the test imediately, should it encounter and error (eg. loss of connection to remote host). However additional information has been made available under warnings. Examples of what is printed under warnings are:
  • prompt timeouts
  • if statement evaluations
  • dynamic variable assignments
  • running in localhost mode 
This section has been deprecated. See expect-lite directives *WARN/*NOWARN

Remote Shell

Expect-lite has been tested, and designed to get along with bash. However others may want to use another shell.

This section has been deprecated. See expect-lite directive **SHELL

Delay to wait for remote host

Because of the nature of accessing a remote host, expect-lite may have to wait for a response if the access is slow (eg. over a VPN via the internet).
# Delay (in ms) to wait for host in Not Expect, and Dynamic Var Capture
set delay_wait_for_host 100
The value of 100 ms is a good value for a local LAN, while 200 ms may be desired if running across high speed internet. As this value is increased the script will run slower. It is recommended that a minimum value be used to prevent scripts from taking too long to run.

Wait for Prompt

What is a prompt? Does it include colour? Does it end in >, $, # ?

There is an implied "wait for prompt" everytime the script writer uses the send command (eg. >ls ) It helps by not issuing the next command before the previous command has completed.

This section has been deprecated. With the support of user defined prompts (in version 3.1.5), it should no longer be necessary to edit this procedure.

User Comment Colour

By default printable comments using the ';' or ';;' are printed in light blue. However there are a range of colour choices which can be set.
# set global color for comment ; or ;; lines
# select one of the following: none, blue, ltblue, gray, ltgray, cyan,
# black, pink, purple
set _el_comment_color ltblue



31 July 2010
http://expect-lite.sourceforge.net/

this document for version 3.7.0 or later