{"id":827,"date":"2018-07-20T02:36:22","date_gmt":"2018-07-20T07:36:22","guid":{"rendered":"https:\/\/www.linuxcloudvps.com\/blog\/?p=827"},"modified":"2023-08-29T10:54:35","modified_gmt":"2023-08-29T15:54:35","slug":"how-to-automate-shell-scripts-with-expect-command","status":"publish","type":"post","link":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/","title":{"rendered":"How to Automate Shell Scripts with Expect Command"},"content":{"rendered":"\n<p>We&#8217;ll show you how to automate shell scripts with expect command. The &#8220;Expect&#8221; name comes from the concept of sending\/waiting for sequences popular by uucp, kermit and various modem management programs. However, not like uucp, Expect is generalized so it can be executed as a user-level command with any program and task in mind. Expect can communicate with multiple programs at the same time. In other words the Expect is a program that talks to a variety of interactive programs according to the script.&nbsp;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>First you need to install the expected package in your system because it is not installed by default. You can install it using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ apt-get install expect<\/pre>\n\n\n\n<p>Or on Red Hat based systems like CentOS:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ yum install expect<\/pre>\n\n\n\n<p>Once installed, you\u2019ll see the expect interpreter as \u201c\/usr\/bin\/expect\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Usage of Expect command<\/h2>\n\n\n\n<p>In order to execute the list of command, the expect command reads from a cmd file. The Expect command could be referred to implicitly to systems that support the #! notation by marking the script as executable and making the first line in the script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/local\/bin\/expect -f<\/pre>\n\n\n\n<p>The \/usr\/local\/bin path is just an example. Of course, the path must be exactly where the Expect is located.<\/p>\n\n\n\n<p>The -c flag prelude a command to execute before any of the scripts. To prevent breaking by the shell the command has to be quoted. We can use this option multiple times. Multiple commands can be executed with only one -c by dividing them with a semicolon. The commands are executed in the order in which they appear.<\/p>\n\n\n\n<p>The -d flag provides a certain diagnostic output, which mainly reports the internal activity of the commands like expect and interact. This flag has the same effect as &#8220;exp_internal 1&#8221; at the beginning of the Expect script, plus the version of Expect is printed.<\/p>\n\n\n\n<p>The -D flag provides an interactive debugger. An integer value should be followed. If the value is non-zero the debugger will take control before the next Tcl procedure or if it is pressed ^C or the breakpoint is interrupted, or another appropriate command for the debugger appears in the script. This option is listed as -Debug if you are using Expectk.<\/p>\n\n\n\n<p>The -f flag begins a directory from which to read commands. This flag is available as a choice because it is handy when using #! notation so can submit the other arguments to the command line. This option is identified as -file If you are using Expectk.This option is identified as -file If you are using Expectk.<\/p>\n\n\n\n<p>Typically, the command file is read into memory and executed in its totality. Sometimes it is desirable to read files on one line at a time. In order to force arbitrary files to be handled this way, we can use the -b flag. This option is specified as -buffer if you are using Expectk.<\/p>\n\n\n\n<p>If the string &#8220;-&#8221; is supplied as a filename, instead of the standard input, it is read. To read from a file actually named &#8220;-&#8221; use the &#8220;.\/-&#8221; string.<\/p>\n\n\n\n<p>The -i flag causes Expect to interactively prompt for commands rather than reading them from a file. Prompting is terminated via the exit command or upon EOF. The -i flag is assumed if neither a command file neither -c is used. Once using Expectk, this feature is specified as -interactive.<\/p>\n\n\n\n<p>&#8212; could also be used to delimit the end of the choices. This can be useful if you want to pass the argument as an option to your script, and not to be interpreted by the Expect. This may be usefully be placed within the #! line to avoid any flaglike interpretation by Expect. For example, the original arguments together with the script name may be left within the variable argv .<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/local\/bin\/expect --<\/pre>\n\n\n\n<p>The file $ exp_library\/expect.rc is automatically generated if it is present unless the -N flag is used. (When using Expectk, this feature is specified as -NORC.) instantly once this, the file ~\/.expect.rc is sourced automatically, unless the -n flag is used. If the environment variable DOTDIR is defined, it&#8217;s treated as a directory and .expect.rc is read from there. once using Expectk, this feature is specified as -norc. This sourcing happens only when executing any -c flags.<\/p>\n\n\n\n<p>-v causes Expect to print its version number and exit. The appropriate flag in Expectk, which uses long-flags names, is a -version.<\/p>\n\n\n\n<p>The optional arguments are created in the list and stored within a variable called argv and. argc is initialized to the length of argv.<\/p>\n\n\n\n<p>Argv0 is defined as the script name or binary if the script is not used. For instance, the following prints out the name of the script and also the first 3 arguments:<\/p>\n\n\n\n<p>The following four Expect commands are used when automating any interactive processes.<\/p>\n\n\n\n<p>send \u2013 The send command is used to send a response to a script or program.<br>expect \u2013 The expect command waits for entry. In other words is waiting for the program output.<br>spawn \u2013 The spawn command is used to launch a script or program such as shell, SSH, FTP, Telnet, SCP and so on. Basically, it will start a script or a program.<br>interact &#8211; The interact command allows you to interact with your program. This means that the interact command it says to expect command to release the terminal so you can write things and do things.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Expect command examples<\/h2>\n\n\n\n<p>Let&#8217;s write a shell script that will ask some questions, and then we can make an Expect script that will answer those questions.<\/p>\n\n\n\n<p>We will begin by creating a shell script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\n\necho \"Hello, how are you doing today?\"\n\nread $ANSWER\n\necho \"May I ask you some questions?\"\n\nread $ANSWER\n\necho \"What is your favorite color?\"\n\nread $ANSWER<\/pre>\n\n\n\n<p>Next, we will type the Expect scripts that will answer on the questions automatically:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset timeout -1\n\nspawn .\/questions\n\nexpect \"Hello, how are you doing today?\\r\"\n\nsend -- \"Thanks, I am great.\\r\"\n\nexpect \"May I ask you some questions?\\r\"\n\nsend -- \"Of course\\r\"\n\nexpect \"What is your favorite color?\\r\"\n\nsend -- \"White\\r\"\n\nexpect eof<\/pre>\n\n\n\n<p>The expect command path is defined in the first line which is #!\/usr\/bin\/expect. On the second line of code, we have disabled the timeout. Then run our script using the spawn command. We can use spawn to run any interactive script or program we want. The other rows that remain are the Expect script that connects to our shell script. Last line if the end of the file which means is the end of the interaction.<\/p>\n\n\n\n<p>Now it&#8217;s time to run the script, just make sure the script is executable.<\/p>\n\n\n\n<p>If the script is not executable, then you can use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod +x .\/answerbot<\/pre>\n\n\n\n<p>And of course, the execute command to run our script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$.\/answerbot<\/pre>\n\n\n\n<p>From this example we can see that we did not communicate with our script at all, the Expect program did the job for us.<\/p>\n\n\n\n<p>The above method can be used for any interactive script or program. Although the script above is very simple to write, perhaps the Expect script is a little inconvenient for some people, you have it well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using autoexpect command<\/h2>\n\n\n\n<p>You can the use autoexpect command if you want to build an expect script automatically.<\/p>\n\n\n\n<p>The autoexpect command works like the expect command, the deference is that the autoexpect will build the automation script for you. The script you want to automate will be passed to autoexpect as a parameter and when you answer the questions and your answers will be saved in a file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ autoexpect .\/questions<\/pre>\n\n\n\n<p>After we run the above command, a single file will be generated called script.exp this file will contain the same code as we did on the previous example but also will have some add-ons that we will skip for now.<\/p>\n\n\n\n<p>It should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># -Don\n#\n\nset timeout -1\nspawn .\/questions\nmatch_max 100000\nexpect -exact \"Hello, how are you doing today?\\r\n\"\nsend -- \"Fine thanks you\"\nexpect -exact \"Fine thanks you\"\nsend -- \"\\r\"\nexpect -exact \"\\r\nMay I ask you some questions?\\r\n\"\nsend -- \"Sure\\r\"\nexpect -exact \"Sure\\r\nWhat is your favorite color?\\r\n\"\nsend -- \"White\\r\"\nexpect eof<\/pre>\n\n\n\n<p>When we run the auto-generated file script.exp, we can see the same answers as awaited:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">spawn .\/questions\nHello, how are you doing today?\nFine thanks you\nMay I ask you some questions?\nSure\nWhat is your favorite color?\nWhite<\/pre>\n\n\n\n<p>There are many commands that produce a variable output, such as FTP programs, the expected script may fail or get stuck. To resolve this problem, you can use wildcards for the variable data to make your script more flexible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Working with Variables<\/h2>\n\n\n\n<p>In the next example, we will show you how to set the variables and how to use them with Expect script.<\/p>\n\n\n\n<p>The set command is using to define variables in Expect scripts like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">set TESTVAR 5<\/pre>\n\n\n\n<p>To access the variable, precede it with $ like this $EXAMPLE<\/p>\n\n\n\n<p>To define the arguments of the command line in the Expect scripts, we are going to use the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">set TESTVAR [lindex $argv 0]<\/pre>\n\n\n\n<p>Here we define a variable TESTVAR which is equal to the first given argument.<\/p>\n\n\n\n<p>You can get the first and the second arguments and store them in variables like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">set mood [lindex $argv 0]\n\nset color [lindex $argv 1]<\/pre>\n\n\n\n<p>Let\u2019s add variables to our script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset mood [lindex $argv 0]\n\nset color [lindex $argv 1]\n\nset timeout -1\n\nspawn .\/questions\n\nexpect \"Hello, how are you doing today?\\r\"\n\nsend -- \"Im $mood\\r\"\n\nexpect \"May I ask you some questions?\\r\"\n\nsend -- \"Of course\\r\"\n\nexpect \"What is your favorite color?\\r\"\n\nsend -- \"$color\\r\"\n\nexpect eof<\/pre>\n\n\n\n<p>Now try to run the Expect script with some parameters to see the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ .\/answerbot SomeMood SomeColor<\/pre>\n\n\n\n<p>We just created our dynamic automated Expect script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using conditional tests<\/h2>\n\n\n\n<p>By using braces as shown in the following example you can create conditional tests:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">expect {\n\n\"example\" { send -- \"send example\\r\" }\n\n\"*lesson\" { send -- \"send lesson\\r\" }\n\n}<\/pre>\n\n\n\n<p>Now we will change our script to return different conditions, and after that, we will change the expect script to deal with these conditions.<\/p>\n\n\n\n<p>We are going to imitate different expectations with the following script:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\n\nlet number=$RANDOM\n\nif [ $number -gt 24000 ]\n\nthen\n\necho \"What is your favorite food?\"\n\nelse\n\necho \"What is your favorite drink?\"\n\nfi\n\nread $ANSWER<\/pre>\n\n\n\n<p>A random number is generated every time you start the script and based on that number, we have set to return different expectations.<\/p>\n\n\n\n<p>The next part is to make our expect script will deal with that.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset timeout -1\n\nspawn .\/questions\n\nexpect {\n\n\"*food?\" { send -- \"Pizza\\r\" }\n\n\"*drink?\" { send -- \"Lemonade\\r\" }\n\n}\n\nexpect eof<\/pre>\n\n\n\n<p>If the script hits the food output, the expect script will send pizza and if the script hits drink output the expect script will send lemonade.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example with expect command in if\/else conditions<\/h2>\n\n\n\n<p>The following example is how to use if\/else clauses in expect scripts:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset NUM 14\n\nif { $NUM &lt; 99 } {\n\nputs \"\\Smaller than 99\\n\"\n\n} elseif { $NUM &gt; 99 } {\n\nputs \"\\Bigger than 99\\n\"\n\n} else {\n\nputs \"\\Equals 99\\n\"\n\n}<\/pre>\n\n\n\n<p>Note: The opening brace needs to be on the same line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using while loops<\/h2>\n\n\n\n<p>In expect language when we are using while loops we need to use braces like in the following example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset NUM 1\n\nwhile { $NUM &lt;= 10 } {\n\nputs \"\\nNumber is $NUM\"\n\nset NUM [ expr $NUM + 1 ]\n\n}\n\nputs \"\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example with For Loops<\/h2>\n\n\n\n<p>To create a for loop in expect, we need to specify three fields, like in the following example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nfor {set NUM 1} {$NUM &lt;= 10} {incr NUM} {\n\nputs \"\\nNUM = $NUM\"\n\n}\n\nputs \"\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How to use user-defined functions<\/h2>\n\n\n\n<p>In the next example, we will show you how to define a function by using the proc.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">proc testfunc { TOTAL } {\n\nset TOTAL [expr $TOTAL + 1]\n\nreturn \"$TOTAL\"\n\n}<\/pre>\n\n\n\n<p>And after that you can use them.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nproc testfunc { TOTAL } {\n\nset TOTAL [expr $TOTAL + 1]\n\nreturn \"$TOTAL\"\n\n}\n\nset NUM 1\n\nwhile {$NUM &lt;= 10} {\n\nputs \"\\nNumber $NUM\"\n\nset NUM [testfunc $NUM]\n\n}\n\nputs \"\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Our last example will be about the interact command.<\/h2>\n\n\n\n<p>Sometimes the expect script contains some sensitive information that you do not want to share with other users who use your expect scripts, such as passwords or other data, so you want your script to take this password from you and continue automation normally.<\/p>\n\n\n\n<p>The interact command will return the control back to the keyboard. When this command is executed, the expect command will begin to read from the keyboard.<\/p>\n\n\n\n<p>This shell script will ask for the password as presented in the example below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash\n\necho \"May I ask who are you?\"\n\nread $ANSWER\n\necho \"Can you provide me with your password?\"\n\nread $ANSWER\n\necho \"What is your favorite color?\"\n\nread $ANSWER<\/pre>\n\n\n\n<p>Now we will create the expect script that will prompt for the password:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/expect -f\n\nset timeout -1\n\nspawn .\/questions\n\nexpect \"*who are you?\\r\"\n\nsend -- \"Hello my name is Thomas\\r\"\n\nexpect \"*password?\\r\"\n\ninteract ## return\n\nsend \"\\r\"\n\nexpect \"*color?\\r\"\n\nsend -- \"White\\r\"\n\nexpect eof<\/pre>\n\n\n\n<p>After you enter your password type ## if you want the control to return back from the keyboard to the script.<\/p>\n\n\n\n<p>The expected language is ported into many languages like C #, Java, Perl, Python, Ruby, and Shell with almost the same concepts and syntax.<\/p>\n\n\n\n<p>Expect scripting language is used in QA, network measurements, such as echo response time, automating file transfer, upgrades, updates, and many other uses<\/p>\n\n\n\n<p>We hope that we help you to understand some of the most important aspects of Expect command, autoexpect command and how to use them.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>If you liked this post on How to automate shell scripts with expect command, please share it with you friends on social media, or if you have any question regarding this blog post, please leave a comment and one of our system administrators will reply to it. Thanks!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ll show you how to automate shell scripts with expect command. The &#8220;Expect&#8221; name comes from the concept of sending\/waiting for sequences popular by uucp, kermit and various modem management programs. However, not like uucp, Expect is generalized so it can be executed as a user-level command with any program and task in mind. Expect &#8230; <a title=\"How to Automate Shell Scripts with Expect Command\" class=\"read-more\" href=\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\" aria-label=\"More on How to Automate Shell Scripts with Expect Command\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":828,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[155,19,20],"class_list":["post-827","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-automate","tag-script","tag-shell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog<\/title>\n<meta name=\"description\" content=\"We&#039;ll show you how to automate shell scripts with expect command. The &quot;Expect&quot; name comes from the concept of sending\/waiting for sequences popular by\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog\" \/>\n<meta property=\"og:description\" content=\"We&#039;ll show you how to automate shell scripts with expect command. The &quot;Expect&quot; name comes from the concept of sending\/waiting for sequences popular by\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxCloudVPS Blog\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/LinuxCloudVPS\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-20T07:36:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-29T15:54:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@LinuxCloudVPS\" \/>\n<meta name=\"twitter:site\" content=\"@LinuxCloudVPS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/person\/ed907227ee7d151c617e6d0fe74f531a\"},\"headline\":\"How to Automate Shell Scripts with Expect Command\",\"datePublished\":\"2018-07-20T07:36:22+00:00\",\"dateModified\":\"2023-08-29T15:54:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\"},\"wordCount\":1884,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg\",\"keywords\":[\"automate\",\"script\",\"shell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\",\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\",\"name\":\"How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg\",\"datePublished\":\"2018-07-20T07:36:22+00:00\",\"dateModified\":\"2023-08-29T15:54:35+00:00\",\"description\":\"We'll show you how to automate shell scripts with expect command. The \\\"Expect\\\" name comes from the concept of sending\/waiting for sequences popular by\",\"breadcrumb\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage\",\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg\",\"contentUrl\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg\",\"width\":600,\"height\":300,\"caption\":\"How to Automate Shell Scripts with Expect Command\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.linuxcloudvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Automate Shell Scripts with Expect Command\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#website\",\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/\",\"name\":\"LinuxCloudVPS\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.linuxcloudvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#organization\",\"name\":\"LinuxCloudVPS\",\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"contentUrl\":\"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2023\/08\/logo.png\",\"width\":217,\"height\":25,\"caption\":\"LinuxCloudVPS\"},\"image\":{\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"http:\/\/www.facebook.com\/LinuxCloudVPS\",\"https:\/\/x.com\/LinuxCloudVPS\",\"http:\/\/www.linkedin.com\/company\/linuxcloudvps-com\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/person\/ed907227ee7d151c617e6d0fe74f531a\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/www.linuxcloudvps.com\/\"],\"url\":\"https:\/\/www.linuxcloudvps.com\/blog\/author\/r0s3admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog","description":"We'll show you how to automate shell scripts with expect command. The \"Expect\" name comes from the concept of sending\/waiting for sequences popular by","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/","og_locale":"en_US","og_type":"article","og_title":"How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog","og_description":"We'll show you how to automate shell scripts with expect command. The \"Expect\" name comes from the concept of sending\/waiting for sequences popular by","og_url":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/","og_site_name":"LinuxCloudVPS Blog","article_publisher":"http:\/\/www.facebook.com\/LinuxCloudVPS","article_published_time":"2018-07-20T07:36:22+00:00","article_modified_time":"2023-08-29T15:54:35+00:00","og_image":[{"width":600,"height":300,"url":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@LinuxCloudVPS","twitter_site":"@LinuxCloudVPS","twitter_misc":{"Written by":"admin","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#article","isPartOf":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/"},"author":{"name":"admin","@id":"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/person\/ed907227ee7d151c617e6d0fe74f531a"},"headline":"How to Automate Shell Scripts with Expect Command","datePublished":"2018-07-20T07:36:22+00:00","dateModified":"2023-08-29T15:54:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/"},"wordCount":1884,"commentCount":1,"publisher":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage"},"thumbnailUrl":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg","keywords":["automate","script","shell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/","url":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/","name":"How to Automate Shell Scripts with Expect Command | LinuxCloudVPS Blog","isPartOf":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage"},"image":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage"},"thumbnailUrl":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg","datePublished":"2018-07-20T07:36:22+00:00","dateModified":"2023-08-29T15:54:35+00:00","description":"We'll show you how to automate shell scripts with expect command. The \"Expect\" name comes from the concept of sending\/waiting for sequences popular by","breadcrumb":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#primaryimage","url":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg","contentUrl":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2018\/07\/How-to-Automate-Shell-Scripts-with-Expect-Command.jpg","width":600,"height":300,"caption":"How to Automate Shell Scripts with Expect Command"},{"@type":"BreadcrumbList","@id":"https:\/\/www.linuxcloudvps.com\/blog\/how-to-automate-shell-scripts-with-expect-command\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.linuxcloudvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Automate Shell Scripts with Expect Command"}]},{"@type":"WebSite","@id":"https:\/\/www.linuxcloudvps.com\/blog\/#website","url":"https:\/\/www.linuxcloudvps.com\/blog\/","name":"LinuxCloudVPS","description":"","publisher":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.linuxcloudvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.linuxcloudvps.com\/blog\/#organization","name":"LinuxCloudVPS","url":"https:\/\/www.linuxcloudvps.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2023\/08\/logo.png","contentUrl":"https:\/\/www.linuxcloudvps.com\/blog\/wp-content\/uploads\/2023\/08\/logo.png","width":217,"height":25,"caption":"LinuxCloudVPS"},"image":{"@id":"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["http:\/\/www.facebook.com\/LinuxCloudVPS","https:\/\/x.com\/LinuxCloudVPS","http:\/\/www.linkedin.com\/company\/linuxcloudvps-com"]},{"@type":"Person","@id":"https:\/\/www.linuxcloudvps.com\/blog\/#\/schema\/person\/ed907227ee7d151c617e6d0fe74f531a","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"admin"},"sameAs":["http:\/\/www.linuxcloudvps.com\/"],"url":"https:\/\/www.linuxcloudvps.com\/blog\/author\/r0s3admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":2,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"predecessor-version":[{"id":1967,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions\/1967"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/media\/828"}],"wp:attachment":[{"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcloudvps.com\/blog\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}