{"id":3,"date":"2011-05-02T07:13:11","date_gmt":"2011-05-02T13:13:11","guid":{"rendered":"http:\/\/mattdturner.com\/wordpress\/?p=3"},"modified":"2011-10-24T06:22:54","modified_gmt":"2011-10-24T12:22:54","slug":"using-linux-expect-to-automate-interactive-processes","status":"publish","type":"post","link":"http:\/\/mattdturner.com\/wordpress\/2011\/05\/using-linux-expect-to-automate-interactive-processes\/","title":{"rendered":"Using Linux Expect to Automate Interactive Processes"},"content":{"rendered":"<p><a href=\"http:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/04\/Linux-Complete-Command-Reference.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-145 alignright\" title=\"Linux-Complete-Command-Reference\" src=\"http:\/\/mattdturner.com\/wordpress\/wp-content\/uploads\/2011\/04\/Linux-Complete-Command-Reference.jpg\" alt=\"\" width=\"282\" height=\"226\" \/><\/a>Have you ever wanted to make a script to handle a repetitive process that requires interaction?  Well, you can with Expect.<\/p>\n<p>No I&#8217;m sure that there are a multitude of uses for Expect, however I have only used it for 1 thing; password entry. \u00a0When building the CMAQ Adjoint model, we have a script that will checkout many modules (approx. 15) from a CVS repository. \u00a0For 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. \u00a0The problem that arose was that the user only has 2 minutes to enter the password before access to the CVS would be killed.<\/p>\n<p><!--more-->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. \u00a0It 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.<\/p>\n<p>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. \u00a0But, I had never used Expect before and was strapped for time and didn&#8217;t think it would be an effective use of my time to learn to write an Expect script.<\/p>\n<p>So I relied upon the <code>autoexpect<\/code> command to create the expect script for me. \u00a0Using the <code>autoexpect<\/code> command is simple; in my case, I would normally run the build script with the following command:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">.\/bldit.cctm_adj<\/pre>\n<p>To use autoexpect, I would just issue the following command:<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">autoexpect .\/bldit.cctm_adj<\/pre>\n<p>and then enter my password when prompted.<\/p>\n<p>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. \u00a0All the password entry is automated, and I no longer have to sit and wait to enter a password multiple times.<\/p>\n<p>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 (<a href=\"http:\/\/www.cyberciti.biz\/tips\/linux-how-to-encrypt-and-decrypt-files-with-a-password.html\" class=\"broken_link\">using gpg<\/a>) when I am not using it.<\/p>\n<p>For more information on the Expect command please see this post (EDIT: page seems to have been removed.) on Linux.com<\/p>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" src=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=93e06585-2faa-4ad4-9c72-9e0bfd6971dc\" alt=\"Enhanced by Zemanta\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wanted to make a script to handle a repetitive process that requires interaction? Well, you can with Expect. No I&#8217;m sure that there are a multitude of uses for Expect, however I have only used it for 1 thing; password entry. \u00a0When building the CMAQ Adjoint model, we have a script that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,64,11,20],"tags":[124,128,122,123,50,104,127,254,23,126,48,90],"class_list":["post-3","post","type-post","status-publish","format-standard","hentry","category-command-line","category-linux-2","category-mac","category-scripting","tag-automate","tag-concurrent-versions-system","tag-expect","tag-interactive","tag-linux","tag-password","tag-secure-shell","tag-security","tag-source-code","tag-tools","tag-unix","tag-user-computing","no-thumb"],"_links":{"self":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/3"}],"collection":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3"}],"version-history":[{"count":11,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/3\/revisions"}],"predecessor-version":[{"id":286,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/3\/revisions\/286"}],"wp:attachment":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}