Using Linux Expect to Automate Interactive Processes

Have you ever wanted to make a script to handle a repetitive process that requires interaction? Well, you can with Expect.

No I’m sure that there are a multitude of uses for Expect, however I have only used it for 1 thing; password entry.  When building the CMAQ Adjoint model, we have a script that will checkout many modules (approx. 15) from a CVS repository.  For each module, the user must input his/her password, then wait for the module to be checked out and downloaded, then enter the password again for the next module.  The problem that arose was that the user only has 2 minutes to enter the password before access to the CVS would be killed.

Some people had suggested setting up passwordless SSH to the CVS server, however this was not an option as my user account did not have access to create any file on the server.  It was also suggested to setup CVSRoot to use pserver and include the password in the environment variable, however again this would not work as pserver was not enabled.

This left me with only 1 option (that I could think of, there are probably more options); to use Expect to automate the password entry.  But, I had never used Expect before and was strapped for time and didn’t think it would be an effective use of my time to learn to write an Expect script.

So I relied upon the autoexpect command to create the expect script for me.  Using the autoexpect command is simple; in my case, I would normally run the build script with the following command:

./bldit.cctm_adj

To use autoexpect, I would just issue the following command:

autoexpect ./bldit.cctm_adj

and then enter my password when prompted.

Now that the script has been automatically generated for me, I just had to rename the script and run it each time I wish to build the model with a new configuration.  All the password entry is automated, and I no longer have to sit and wait to enter a password multiple times.

I know some people will say that having a script that contains your password is not very secure, however access to this computer is very secure and I keep the script encrypted (using gpg) when I am not using it.

For more information on the Expect command please see this post (EDIT: page seems to have been removed.) on Linux.com

Enhanced by Zemanta

2 thoughts on “Using Linux Expect to Automate Interactive Processes

  1. […] any type of programming or scripting, I do my best to streamline everything (see this post and this post).  Basically anything I do in the Terminal that can be automated, I try to automate.  In addition […]

  2. I visited many web pages but the audio feature for audio
    songs existing at this web site is actually wonderful.
    http://www.just-exercise.com recently posted..http://www.just-exercise.comMy Profile

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.