expect-lite Installation and Quick Start Guide
Author: Craig Miller

# 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/rpm/deb package includes the latest expect-lite, as well as over 25 examples. Or, if you are running a modern version of Ubuntu: apt-get install expect-lite Or, if you are running a modern version of gentoo: emerge -auv expect-lite Or, download the RPM or DEB file (from sourceforge) and install using 'sudo rpm -Uv expect-lite*.rpm' or 'sudo dpkg -i expect-lite*deb' Then use the '/usr/share/doc/expect-lite/install.sh -c' to configure ssh and .bashrc if desired ## Quick Install To install using the tar.gz file: Prior to untaring the package, be sure to type 'umask 0' to preserve permissions of the package. Untar the expect-lite package, and use the included install.sh script (as of version 4.0.2). If on Linux/Unix/MacOS X, sudo permissions will be required to install: Change directory to expect-lite.proj
    cd expect-lite.proj
Run installer
    sudo ./install.sh
Since cygwin does not require sudo previlages, just type:
    ./install.sh
Test by typing at the prompt:
    expect-lite
If you see the help, then it is ready to go, installation is complete! The install.sh has other options such as unprivileged install, and user configure only, which may be useful in your environment, refer to ./install.sh -h for more info. ## 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: a script 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 check result ====
    @5
    >ping  localhost
    <<127.0.0.1
    <<127.0.0.1
    <<127.0.0.1
    >>^C
    >
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
There should be output that looks similar to the following:
    cvmiller@maile:~/Freescale$
    cvmiller@maile:~/Freescale$ ping 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.020 ms
    64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.023 ms
    sending ^C

    ^C
    --- localhost ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1007ms
    rtt min/avg/max/mdev = 0.020/0.021/0.023/0.004 ms

    ##Overall Result: PASS
Congratulations you have just run your first expect-lite script! expect-lite is designed to run in a multi-user environment, utilizing shell variables to set one's preferences. ## Customizing expect-lite There are aspects of expect-lite which you may want to tune to your environment. The Installer will set up your .bashrc file to source the expect-lite configuration from .expect-literc. Customization is controlled through shell environment variables. A sample bashrc file is supplied in the expect-lite package. The contents of which are as follows:
    # bashrc

    # append this sample bashrc to your .bashrc to set customize expect-lite

    # remote host to connect, default=none
    # 	expect-lite was designed to automate server farm environments
    #	However, it can also be run from the local machine or PC by setting
    #	this value to 'none'. The CLI option -r <rhost> will overide this value
    #export EL_REMOTE_HOST=localhost

    # name of expect-lite script
    #	Good for testing one script over and over
    #export EL_CMD_FILE=

    # change to this dir upon login
    #export EL_USER_DIR=

    # Login method to remote host
    #	expect-lite includes a utilty (setup_local_ssh.sh) to automatically setup ssh
    #	keys for the user to use with the localhost. This is the fastest method
    #	of script execution, much faster than 'none'.
    #	Choose one login method: telnet|ssh|ssh_key|none
    #export EL_CONNECT_METHOD=ssh_key
    export EL_CONNECT_METHOD=none

    # username for telnet|ssh|ssh_key access methods
    # User is also used by ssh_key method as well. If user is blank then the default
    #	user will be used (the user running the script). However if $user is defined
    #	then ssh_key will use the following command: ssh $user@$host
    #export EL_CONNECT_USER=

    # password for telnet|ssh access methods
    #export EL_CONNECT_PASS=

    # 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
    #export EL_DELAY_WAIT_FOR_HOST=

    # User defined constants
    #EL_*
## EL_CONNECT_METHOD expect-lite was designed for a server farm environment, and as such can automatically connect and log into a remote host. expect-lite supports three methods to connect to remote hosts. Expect-lite supports three connection methods: telnet ssh ssh_key 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.
    # Login method to remote host
    #	expect-lite includes a utilty (setup_local_ssh.sh) to automatically setup ssh
    #	keys for the user to use with the localhost. This is the fastest method
    #	of script execution, much faster than 'none'.
    #	Choose one login method: telnet|ssh|ssh_key|none
    export EL_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 (including in the Cygwin environment). To invoke this method the value of "none" is given for the remote host on the command line.
    expect-lite -r none -c 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 'none'. The installer will detect if the install machine is running sshd, if so it will configure .expect-literc to use 'ssh_keys" and run the provided shell script 'setup_local_ssh.sh' (in the Tools directory) which will setup the localhost with ssh keys. This can also be one manually at a later time, it is only necessary to run it once:
    ./Tools/setup_local_ssh.sh
## EL_CONNECT_USER & EL_CONNECT_PASS The connection methods telnet & ssh require user name and password. A different user can be used for the ssh_key method as well, by setting EL_CONNECT_USER. The ssh_key is most secure since the user name and passwords are not used. However this may not be practical for your environment.
    # username for telnet|ssh|ssh_key access methods
    # User is also used by ssh_key method as well. If user is blank then the default
    #	user will be used (the user running the script). However if $user is defined
    #	then ssh_key will use the following command: ssh $user@$host
    #export EL_CONNECT_USER=

    # password for telnet|ssh access methods
    #export EL_CONNECT_PASS=
The default username and passwords are blank, and are not used for the 'none' connection method. ## EL_DELAY_WAIT_FOR_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
    # 100 ms is a good value for a local LAN, 200 ms if running across high speed internet
    #export EL_DELAY_WAIT_FOR_HOST=
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. ## EL_* The last section of the sample bashrc file is reserved for the user. expect-lite will read in any shell environment variable which begins with EL_ The shell variables are treated as constants in the expect-lite script, overriding any internal variables.
    # User defined constants
    #export EL_*
    export EL_root_pass=mysecret

19 November 2013
http://expect-lite.sourceforge.net/
this document for version 4.6.2 or later