EXPECT-LITE(1)

πŸ’– expect-lite β€” EXPECT-LITE(1) (User Commands) πŸ’–

Okay bestie, welcome to the expect-lite manual page, and it's giving main character energy for your terminal automation era. ✨ No cap, this is the part where you learn the whole vibe. πŸ¦‹


✨ NAME ✨

expect-lite β€” a quick and easy command line automation tool. Periodt, that's the name, and it ate. πŸ’…

✨ SYNOPSIS ✨

Two ways to run it, bestie. Lowkey iconic: πŸ’–

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

First form is the expect-lite command, second form is running script.elt directly. Both understand -vv, host options, CONSTANT=value, *DIRECTIVE, and -h|--help in the exact positions above. 🫢

✨ DESCRIPTION ✨

So here's the tea, bestie: it's written in Expect, and it's designed to directly map an interactive terminal session into an automation script. The 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 β€” literally, you can skip that whole era. 🧚 ngl, that's the vibe check.

Usage, long form:

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

Or the short form, because we're efficient queens: πŸ‘‘

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

Example, fr fr:

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> πŸ”

Example with login, because slay:

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)

Example with debug:

eg. ./expect-lite -v r=host-008 c=pm_alt.elt

User defined help options: -h|--help 🫢

  • -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 πŸ’–

okay bestie, this is just the quick rundown β€” a little cheat sheet for the girlies who already know expect-lite and just need a nudge to remember stuff. For the full ✨complete✨ descriptions you gotta go read the other docs (the html document, specifically). No cap.


🌸 Special Characters 🌸

  • > β€” wait for a prompt, then send your string off to the remote host 🫢
  • >> β€” send the string to the remote host, no waiting for a prompt, just vibes
  • < β€” this string/regex MUST come back from the remote host inside the allotted timeout, or the script will FAIL! 😭
  • << β€” literal string that MUST be received (basically < but with no regex evaluation, so it's giving ✨simple✨)
  • -< β€” the NOT expect. if that string/regex does show up from the remote host, the script FAILS! πŸ’€
  • ~< β€” the fuzzy expect, for when you're expecting an approximate number (decimal or hex, either one)
  • # β€” comment lines, they do absolutely nothing and that's iconic
  • ; β€” also comment lines, but these get printed to stdout (for logging purposes, iykyk)
  • ;<colour> comment β€” custom colour comment lines! colour can be blue, ltblue, gray, ltgray, cyan, black, pink, purple, red, green, yellow
  • ;; β€” same as above but no extra newlines get printed (super handy for printing script help)
  • ;;; β€” marks the beginning and ending of a block of help text. Help Text is user defined help for a script, and it gets printed when -h or --help is on the command line
  • @num β€” changes the expect timeout to num seconds
  • :num β€” sleeps for num seconds. Mili-seconds are supported too, e.g. :1.005 is 1005 mili-seconds
  • $var= β€” static variable assignment at script invocation. Variable names are limited to letters, numbers, and underscore
  • +$var= β€” dynamic variable assignment
  • +$var β€” increment the value of $var by 1 decimal
  • -$var β€” decrement the value of $var by 1 decimal
  • =$var β€” math functions, performs bitwise and arithmetic operations: << >> & | ^ * / % + - (see math functions)
  • =$str β€” string math functions, if $str is a string, performs 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 blocks are supported in the action and else_action statements too, 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, also using code blocks, where each iteration $item gets assigned the next item in the list. The 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 an expect-lite script file, which is super useful for making common variable files, or 'subprograms/subroutines'. You can pass optional parameters which will override (as constants) the variables in the include file. Constant values passed may have spaces, and 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 the script, and returns the value of N. if N isn't specified it returns 0
  • *PASS β€” immediately terminates the script, and returns 0 (pass) ✨
  • *FAIL β€” immediately fails the script, and returns 1 (fail), unless *NOFAIL is set, in which case the script will run to completion, and return 1
  • *NOFAIL β€” the script will run to completion, and returns 1 if a failure occurred during execution, or 0 if it passed. (it's a sticky flag, and it can not be unset)
  • **SHELL=<shell> β€” configuration directive which sets the shell immediately after automatic login to the remote host (see setting the shell)
  • *INTERACT β€” a breakpoint which places the user in interact mode, pauses the script, and turns control of the keyboard over to the user πŸŽ€
  • *NOINTERACT β€” once set, it will ignore all succeeding breakpoints (*INTERACT). This lets you run a script or scripts in an unattended regression. This can not be unset (it's 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 the 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 the new value
  • *EOLS LF|*EOLS CRLF β€” controls the end of line sequence sent to the 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, it 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 get the 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 the -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 the default. Timestamps will be written to the log file when *LOG is used.
  • *NOTIMESTAMP β€” disables timestamp printing

🌈 Environment Variables 🌈

Good news bestie: 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's 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 the remote host. Valid options are: none|telnet|ssh|ssh_key. Default is none
  • EL_CONNECT_USER β€” user name to use for login on the remote host (telnet|ssh)
  • EL_CONNECT_PASS β€” password to use for login on the remote host (telnet|ssh)
  • EL_INFINITE_LOOP=N β€” infinite loop protection value, sets N to the 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 you're running across high speed internet
  • EL_REMOTE_HOST β€” name or IP of remote host
  • EL_CMD_FILE β€” name of the expect-lite script to run
  • EL_USER_DIR β€” change to this directory upon login before executing the 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 it 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 a 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 by using instant-interact at anytime during the script execution by pressing ctrl+backslash ^\

  • <esc>s β€” Step, execute the next step in the script
  • <esc>k β€” sKip the next step in the script
  • <esc>c β€” Continue execution of the script
  • <esc>v β€” show Vars, display expect-lite variables and values
  • <esc>e β€” show Environment, display the expect-lite environment
  • <esc>0to9 β€” display the next N lines of script
  • <esc>-1to-9 β€” display the 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 Β© 2008-2015 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.


and that's the whole page bestie, we ate and left no crumbs πŸ’… this was expect-lite version 4.9.0, dated August 2015, filed under EXPECT-LITE(1) β€” go forth and automate, you absolute main character πŸ¦‹βœ¨

πŸ“¦ where this page comes from