expect-lite - Online in the Cloud

This is the command expect-lite that can be run in the OnWorks free hosting provider using one of our multiple free online workstations such as Ubuntu Online, Fedora Online, Windows online emulator or MAC OS online emulator

PROGRAM:

NAME


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

SYNOPSIS


expect-lite [-vv] -c <script> [-r <host>] [CONSTANT=value] [*DIRECTIVE] [-h|--help]
or
script.elt [-vv] [r=<host>] [CONSTANT=value] [*DIRECTIVE] [-h|--help]

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

user defined help options: -h|--help

displays user defined help text (demarcated by ;;;) and variables defined in script
which can be overridden by constants on the command line

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 more complete 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 allotted 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!

~< fuzzy expect, expect an approximate number (decimal or hex)

# used to indicate comment lines, and have no effect

; are also used to indicate comment lines, but are printed to stdout (for 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)

;;; marks beginning and ending of a block of help text. Help Text is user defined help
for a script and is printed when -h or --help is on the command line

@num changes the expect timeout to num of seconds

:num sleeps for num seconds. Mili-seconds also supported e.g. :1.005 is 1005 mili-
seconds

$var= static variable assignment at script invocation. Variable names limited to letters,
numbers, and underscore

+$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)

=$str string math functions, if $str is a string, perform string operations:
//search/replace/ + - (see string math functions in documentation)

! 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 and else_action statements. e.g.
?if $i < $n ? [
>send string
<expect string
]::[
>send else string
<expect else string
]

[ While Loop, using code blocks e.g.
[ $i < $n
+$i
]

Foreach Loop, using code blocks, each iteration $item is assigned the next item in
the list. List must be space delimited e.g.
$thelist=ab cd ef
[ $item=$thelist
>echo $item
]

% label - used for jumping to labels

~filename [constant=value] [constant=value with spaces]
includes a expect-lite script file, useful for creation of common variable files,
or 'subprograms/subroutines'. Can pass optional parameters which will override (as
constants) the variables in the include file. Constant values passed may have
spaces, no quotes are required

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 <N>
Immediately terminates script, and returns the value of N, if N is not specified
returns 0

*PASS Immediately terminates script, and returns 0 (pass)

*FAIL Immediately fails script, and returns 1 (fail), unless *NOFAIL is set, then script
will run to completion, and return 1

*NOFAIL
Script will run to completion, and returns 1, if failure occurred during execution,
or 0, if pass (it is a sticky flag, and can not be unset)

**SHELL=<shell>
Configuration directive which sets the shell immediately 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

*NOINTERACT
Once set, will ignore all succeeding breakpoints (*INTERACT). This permits running
a script or scripts in an unattended regression. This can not be unset (it is a
sticky flag)

*FORK <session>
Multiple session support. Directs expect-lite to open a new session and spawns a
new shell

*SHOW VARS
Debug information, displays all expect-lite variables. Can be used in interact
mode.

*SHOW ENV
Debug information, displays expect-lite environment, including state of directives,
infinite loop counter, log file name (if used), and environment 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.

*DVPROMPT|*NODVPROMPT
Enable/disable the Dynamic Variable capture method to require a trailing prompt
(default=*DVPROMPT).

*NOINCLUDE
Once set, will ignore all succeeding include files (lines starting with ~). This
was the default behaviour in Library mode (introduced in v4.1). This behaviour is
no longer default, and this directive provides a method to previous behavior.

Logging
Logging encompasses two operations: 1) writing script output to a file, 2) controlling
additional messages, such as info, exp_info and warnings. All logging commands when used
on the CLI will override those inside the script

*LOG|*NOLOG
Enable/disable logging of standard out and messages to a file. The log file name
will be <script_name>.log saved in the script directory.(see Environment Variable
EL_LOG_EXT below)

*LOG <file_name>|*LOGAPPEND <file_name>
Enable logging to a user specified path/file_name. When invoked on the CLI, the
specified file_name must end in ".log" (or as defined by EL_LOG_EXT) to avoid
ambiguity

*INFO|*NOINFO
Enable/disable informational messages

*EXP_INFO|*NOEXP_INFO
Enable/disable "expected" messages (additionally 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 with milisecond accuracy, for each command sent, ISO is
default. Timestamps will be written to log file when *LOG is used.

*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 .expect-literc and source it from .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_INFINITE_LOOP=N
Infinite loop protection value, sets N to user's default value

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_SHELL
Start this shell (default bash) when using EL_CONNECT_METHOD=none

EL_DYN_VAR_PROMPT
Set the Dynamic Variable capture method to require a prompt (default=1). Disable by
setting to 0.

EL_LOG_EXT
Set the log file name extension string (default=".log") which is appended to the
script name when using *LOG without file name argument or used to detect a log file
name on the command line.

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>e show Environment, display expect-lite environment

<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

Use expect-lite online using onworks.net services



Latest Linux & Windows online programs