<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: need info on expect script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044924#M64679</link>
    <description>&lt;!--!*#--&gt;It's pretty easy.  The quick-whip-up to catch a few common things is as follows:&lt;BR /&gt;&lt;BR /&gt;--- start ---&lt;BR /&gt;#!/usr/bin/expect&lt;BR /&gt;&lt;BR /&gt;log_user 0&lt;BR /&gt;&lt;BR /&gt;set my_passphrase "passphrase"&lt;BR /&gt;set my_password   "password"&lt;BR /&gt;&lt;BR /&gt;spawn "/usr/bin/ssh" "root@34.343.4.3"&lt;BR /&gt;&lt;BR /&gt;while {1} {&lt;BR /&gt;  expect {&lt;BR /&gt;    "continue connecting (yes/no)?" {&lt;BR /&gt;      send "yes\n"&lt;BR /&gt;    }&lt;BR /&gt;    "passphrase" {&lt;BR /&gt;      send "$my_passphrase\n"&lt;BR /&gt;    }&lt;BR /&gt;    "password" {&lt;BR /&gt;      send "$my_password\n"&lt;BR /&gt;    }&lt;BR /&gt;    -re "(#|\\\$|%) $" {&lt;BR /&gt;      log_user 1&lt;BR /&gt;        send_user "Shell prompt found.  Dropping to shell:"&lt;BR /&gt;        send "\n"&lt;BR /&gt;        break&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;interact&lt;BR /&gt;--- end ---&lt;BR /&gt;&lt;BR /&gt;This has separate variables for pass phrases and pass words.  Passphrases are for local keys if used.  Passwords are for remote authentication.&lt;BR /&gt;&lt;BR /&gt;It also catches the havent-ssh'd-to-the-box-before thing too.&lt;BR /&gt;&lt;BR /&gt;The last bit (the '-re' bit) is the line to see if it finds a shell prompt.  If not, there's a built-in 10 second timeout which will dump you out.&lt;BR /&gt;&lt;BR /&gt;The 'interact' at the end should be fairly self explanatory.&lt;BR /&gt;&lt;BR /&gt;If you want to pass the password/passphrase, then you'll need to mess around with the '[lindex argv]' TCL variable stuff.&lt;BR /&gt;&lt;BR /&gt;If all else fails, try using 'autoexpect'.  It will generate a custom script for you to modify.</description>
    <pubDate>Fri, 27 Jul 2007 05:07:00 GMT</pubDate>
    <dc:creator>Stuart Browne</dc:creator>
    <dc:date>2007-07-27T05:07:00Z</dc:date>
    <item>
      <title>need info on expect script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044923#M64678</link>
      <description>hi all,&lt;BR /&gt;i am trying to write a expect script.which doeas not ask 4 a password.The password shd be inside the expect script.&lt;BR /&gt;ex:i want to connect to root@34.343.4.3 pasword=xxxxx.&lt;BR /&gt;how to do it inside the script.give an example.thnks in advance</description>
      <pubDate>Fri, 27 Jul 2007 04:14:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044923#M64678</guid>
      <dc:creator>Karthik_sg</dc:creator>
      <dc:date>2007-07-27T04:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: need info on expect script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044924#M64679</link>
      <description>&lt;!--!*#--&gt;It's pretty easy.  The quick-whip-up to catch a few common things is as follows:&lt;BR /&gt;&lt;BR /&gt;--- start ---&lt;BR /&gt;#!/usr/bin/expect&lt;BR /&gt;&lt;BR /&gt;log_user 0&lt;BR /&gt;&lt;BR /&gt;set my_passphrase "passphrase"&lt;BR /&gt;set my_password   "password"&lt;BR /&gt;&lt;BR /&gt;spawn "/usr/bin/ssh" "root@34.343.4.3"&lt;BR /&gt;&lt;BR /&gt;while {1} {&lt;BR /&gt;  expect {&lt;BR /&gt;    "continue connecting (yes/no)?" {&lt;BR /&gt;      send "yes\n"&lt;BR /&gt;    }&lt;BR /&gt;    "passphrase" {&lt;BR /&gt;      send "$my_passphrase\n"&lt;BR /&gt;    }&lt;BR /&gt;    "password" {&lt;BR /&gt;      send "$my_password\n"&lt;BR /&gt;    }&lt;BR /&gt;    -re "(#|\\\$|%) $" {&lt;BR /&gt;      log_user 1&lt;BR /&gt;        send_user "Shell prompt found.  Dropping to shell:"&lt;BR /&gt;        send "\n"&lt;BR /&gt;        break&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;interact&lt;BR /&gt;--- end ---&lt;BR /&gt;&lt;BR /&gt;This has separate variables for pass phrases and pass words.  Passphrases are for local keys if used.  Passwords are for remote authentication.&lt;BR /&gt;&lt;BR /&gt;It also catches the havent-ssh'd-to-the-box-before thing too.&lt;BR /&gt;&lt;BR /&gt;The last bit (the '-re' bit) is the line to see if it finds a shell prompt.  If not, there's a built-in 10 second timeout which will dump you out.&lt;BR /&gt;&lt;BR /&gt;The 'interact' at the end should be fairly self explanatory.&lt;BR /&gt;&lt;BR /&gt;If you want to pass the password/passphrase, then you'll need to mess around with the '[lindex argv]' TCL variable stuff.&lt;BR /&gt;&lt;BR /&gt;If all else fails, try using 'autoexpect'.  It will generate a custom script for you to modify.</description>
      <pubDate>Fri, 27 Jul 2007 05:07:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044924#M64679</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2007-07-27T05:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: need info on expect script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044925#M64680</link>
      <description>thnks the script really helped and its working.i have assigned the points.Can u explai a the above script in detail.Thnks</description>
      <pubDate>Fri, 27 Jul 2007 05:47:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044925#M64680</guid>
      <dc:creator>Karthik_sg</dc:creator>
      <dc:date>2007-07-27T05:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: need info on expect script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044926#M64681</link>
      <description>The man page for 'expect' is pretty straight forward, but I'll explain away.&lt;BR /&gt;&lt;BR /&gt;log_user 0&lt;BR /&gt;&lt;BR /&gt;This tells expect to not show any of the spawn's output.  Makes it looks neat 'n pretty :P&lt;BR /&gt;&lt;BR /&gt;set &lt;NAME&gt; &lt;VALUE&gt;&lt;BR /&gt;&lt;BR /&gt;Simple variable assignment.  Strictly speaking, the quotes aren't needed for plain text strings (either here, or in the expect strings), but it makes it easier to differentiate what's what.&lt;BR /&gt;&lt;BR /&gt;spawn &lt;COMMAND&gt; &lt;ARGUMENTS&gt;&lt;BR /&gt;&lt;BR /&gt;This forks off the command, tieing STDIN, STDERR and STDOUT to expect for it to parse/manipulate.&lt;BR /&gt;&lt;BR /&gt;The 'while {1} {' loop is so we don't have to repeat the expect strings over and over.&lt;BR /&gt;&lt;BR /&gt;expect {&lt;BR /&gt;&lt;BR /&gt;The simple form of 'expect' is to take the match string and the command all on the one line (i.e. 'expect "passphrase" send "$my_passphrase\n"').&lt;BR /&gt;&lt;BR /&gt;But as we have multiple possible strings which might match, we use the more open form of the expect command.  From here, we list the possible match texts:&lt;BR /&gt;&lt;BR /&gt;"continue connecting (yes/no)?"&lt;BR /&gt;"passphrase"&lt;BR /&gt;"password"&lt;BR /&gt;-re "(#|\\\$|%) $"&lt;BR /&gt;&lt;BR /&gt;The first three should be straight forward and easy to understand.  The fourth does a 'regular expression' match on the STDOUT string from the spawned process.&lt;BR /&gt;&lt;BR /&gt;The 'send' command is used to send a string to the spawned process's STDIN.&lt;BR /&gt;&lt;BR /&gt;The 'send_user' is to send text to the user's TTY.&lt;BR /&gt;&lt;BR /&gt;The 'break' is to break out of the while loop.&lt;BR /&gt;&lt;BR /&gt;And finally, we come to the:&lt;BR /&gt;&lt;BR /&gt;interact&lt;BR /&gt;&lt;BR /&gt;As I think I mentioned before, this throws back interactive control to your TTY for you to do things with.&lt;/ARGUMENTS&gt;&lt;/COMMAND&gt;&lt;/VALUE&gt;&lt;/NAME&gt;</description>
      <pubDate>Fri, 27 Jul 2007 07:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-info-on-expect-script/m-p/4044926#M64681</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2007-07-27T07:13:50Z</dc:date>
    </item>
  </channel>
</rss>

