expect-lite(1)

EXPECT-LITE(1) User Commands EXPECT-LITE(1)

NAME

expect-lite - a quick and easy command line automation tool

SYNOPSIS

expect-lite [-vv] -c <script> [-r <host>] [CONSTANT=value] [*DIRECTIVE]
or
expect-lite [-vv] c=<script> [r=<host>] [CONSTANT=value] [*DIRECTIVE]

DESCRIPTION

Written in Expect, it is designed to directly map an interactive terminal session into an automation script. expect-lite scripts use punctuation character(s) at the beginning of each line to indicate the action. Basic expect-lite scripts can be created by simply cutting and pasting text from a terminal window into a script, and adding > < characters. Knowledge of Expect is not required.

usage: expect-lite remote_host=<remote_host_IP> cmd_file=<command_file> [user_dir=<user_dir>] [const1=value1] [*DIRECTIVE]

or short form: expect-lite r=<remote_host_IP> c=<command_file> [d=<user_dir>] [const1=value1] [*DIRECTIVE]

eg. ./expect-lite r=host-008 c=pm_alt.elt d=/local/sw myvar=myvalue *NOCOLOR
additional login options: user_name=<username> user_password=<password>
eg. ./expect-lite r=host-008 c=pm_alt.elt u=superuser p=mysecret

additional debug options: -v|-vv|--verbose

-v
prints warnings, and infos (i.e. conditionals, dynamic var assignments)
-vv|--verbose
prints warnings and debug (i.e. expect match info)
eg. ./expect-lite -v r=host-008 c=pm_alt.elt

COMMAND SYNOPSIS

This is just a brief synopsis of expect-lite commands to serve as a reminder to those who already know expect-lite; other documentation (such as the html document) must be consulted for fuller descriptions.

Special Characters

>
wait for a prompt, then send string to the remote host
>>
send string to remote host, without waiting for prompt

<
string/regex MUST be received from the remote host in the alloted timeout or the script will FAIL!
<<
literal string MUST be received (similar to '<' without regex evaluation)
-<
NOT expect, if string/regex IS received from the remote host the script will FAIL!
#
used to indicate comment lines, and have no effect
;
are also used to indicate comment lines, but are printed to stdout ‹r logging
;<colour> comment
add custom colour comment lines, colour may be blue, ltblue, gray, ltgray, cyan, black, pink, purple, red, green, yellow
;;
similar to above, but no extra newlines are printed (useful for printing script help)
@num
changes the expect timeout to num of seconds
$var=
static variable assignment at script invocation
+$var=
dynamic variable assignment
+$var
increment value of $var by 1 decimal
-$var
decrement value of $var by 1 decimal
=$var
math functions, perform bitwise and arithmetic operations: << >> & | ^ * / % + - (see math functions)
!
indicates an embedded expect line
?
c-style if/then/else in the format ?cond?action::else_action. code block are also supported in the action or else_action statements. e.g.
?if $i < $n ? [
>send string
<expect string
]
[
While Loop, using code blocks e.g.
[ $i < $n
+$i
]
%
label - used for jumping to labels
~filename
includes a expect-lite automation file, useful for creation of common variable files, or 'subprograms/subroutines'

Directives

*~filename
Include a fail script, which expect-lite runs only if the main script fails
*/prompt/
Set a user defined prompt (defined in regex)
*TERM or *PASS
Immediately terminates script, but returns 0 (pass)
*FAIL
Immediately fails script, and returns 1 (fail)
*NOFAIL
Script will run to completion, and returns 1, if failure occured during execution, or 0, if pass
**SHELL=<shell>
Configuration directive which sets the shell imediately after automatic login to remote host (see setting the shell)
*INTERACT
A breakpoint which places user in interact mode, and pauses the script and turns control of the keyboard over to the user
*FORK <session>
Multiple session support. Directs expect-lite to open a new session and spawns a newshell
*SHOW VARS
Debug information, displays all expect-lite variables. Can be used in interact mode.
*INFINITE_LOOP N
Infinite loop protection value, sets N as new value
*EOLS LF|*EOLS CRLF
Controls end of line sequence sent to remote host, either line feed, or carriage return + line feed.

Logging

*INFO|*NOINFO
Enable/disable informational messages
*EXP_INFO|*NOEXP_INFO
Enable/disable "expected" messages (addtionally use -V flag to enable)
*WARN|*NOWARN
Enable/disable warning messages
*DEBUG|*NODEBUG
Enable/disable debug messages
*NOCOLOR
Disables color on stdout
*TIMESTAMP <ISO|YMD|DMY|MDY>
Prints Date and Timestamp for each command sent, ISO is default
*NOTIMESTAMP
Disables timestamp printing

Environment Variables

It is no longer necessary to hand edit the expect-lite script itself. All parameters such as connect_method, login name and password are controlled via shell environment variables. This permits individual customization in a multi user environment. It is recommended to save these values in the .bashrc or .cshrc. If set, the following environment variables will be used:

EL_CONNECT_METHOD
The method expect-lite uses to connect to remote host. Valid options are: none|telnet|ssh|ssh_key Default is none
EL_CONNECT_USER
User name to use for login on remote host (telnet|ssh)
EL_CONNECT_PASS
Password to use for login on remote host (telnet|ssh)
EL_DELAY_WAIT_FOR_HOST
Delay (in ms) to wait for host in Not Expect, and Dynamic Var Capture. 100 ms is a good value for a local LAN, 200 ms if running across high speed internet
EL_REMOTE_HOST
Name or IP of remote host
EL_CMD_FILE
Name of expect-lite script to run
EL_USER_DIR
Change to this directory upon login before executing script
EL_*
Any other shell environment variables starting with EL_ will become constants

Debugger (IDE)

The debugger performs three primary functions: 1) connecting the user to the remote host or device under test, 2) monitoring special commands prefaced with the escape key for stepping, and other functions, and 3) the debugger will allow expect-lite script lines to be executed by either typing directly or pasting them into the IDE.

The debugger is invoked at a breakpoint by placing the *INTERACT command in the script, or using by instant-interact at anytime during the script execution by pressing ctrl+backslash ^\

<esc>s
Step, execute next step in script
<esc>k
sKip next step in script
<esc>c
Continue execution of the script
<esc>v
show Vars, display expect-lite variables and values
<esc>0to9
display next N lines of script
<esc>-1to-9
display last N lines of script
ctrl+d
Quit & Exit expect-lite
<esc>h
display Help
[pasted line(s)]
execute any pasted line(s) from a script into the IDE
[type any expect-lite line]
execute any typed expect-lite script line

AUTHOR

Written by Craig Miller

REPORTING BUGS

Report bugs to <cvmiller at gmail dot com>.

COPYRIGHT

Copyright © 2008-2011 Craig Miller
Copyright © 2005-2007 FreeScale Semiconductor and Craig Miller
License BSD-Style: This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

SEE ALSO

The full documentation for expect-lite is maintained as an HTML manual. Please see http://expect-lite.sf.net/ for complete documentation.

October 2011 expect-lite version 4.2.0