<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Fri May 24, 2013 7:28 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Fri May 24, 2013 7:28 am</pubDate>
  <lastBuildDate>Fri May 24, 2013 7:28 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>More Fun and games with expect</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=103074#103074</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=67177'&gt;PeterM&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Dec 01, 2011 1:28 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      And yes, you did read it correctly, I was talking to the cat  &lt;img src=&quot;images/smiles/icon_redface.gif&quot; alt=&quot;Embarassed&quot; border=&quot;0&quot; /&gt; &lt;br /&gt;
I think the cat was listening, the expression didn't change much but at least it didn't roll it's eyes.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=103074#103074</comments>
                                        <author>PeterM</author>
                                        <pubDate>Thu Dec 01, 2011 1:28 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=103074#103074</guid>
                                      </item>
                                      <item>
                                        <title>More Fun and games with expect</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=103073#103073</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=67177'&gt;PeterM&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Dec 01, 2011 1:26 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Me again,&lt;br /&gt;
&lt;br /&gt;
Just as I was starting to go insane, I was talking the problem out loud to the cat and it suddenly hit me. I had the write the file bit in the wrong place.&lt;br /&gt;
Here's some working code for you:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: darkblue&quot;&gt;#!/usr/bin/expect&lt;br /&gt;
# Usage: gwinfo userid password&lt;br /&gt;
set timeout 10&lt;br /&gt;
set mgwyip [lindex $argv 0]&lt;br /&gt;
set userid [lindex $argv 1]&lt;br /&gt;
set password [lindex $argv 2]&lt;br /&gt;
match_max 100000&lt;br /&gt;
&lt;br /&gt;
puts &amp;quot;logging in to $mgwyip\r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
spawn ssh $userid@$mgwyip&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
    -re &amp;quot;continue connect&amp;quot; {send &amp;quot;yes\r&amp;quot;}&lt;br /&gt;
    timeout {puts &amp;quot;Host is known&amp;quot;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
    -re &amp;quot;(P|p)assword: &amp;quot; {send &amp;quot;$password\r&amp;quot;}&lt;br /&gt;
    -re &amp;quot;Warning:&amp;quot; {send &amp;quot;$password\r&amp;quot;}&lt;br /&gt;
    -re &amp;quot;Connection refused&amp;quot; {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    -re &amp;quot;Connection closed&amp;quot;  {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    -re &amp;quot;no address.*&amp;quot; {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    timeout {puts &amp;quot;Timeout error. Device down or unreachable? &amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
	-re &amp;quot;super&amp;quot; {send &amp;quot;show image version\r&amp;quot;}&lt;br /&gt;
	timeout {puts &amp;quot;Error reading prompt -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
	-re &amp;quot;super&amp;quot; {send &amp;quot;exit\r&amp;quot;}&lt;br /&gt;
	timeout {puts &amp;quot;Error reading prompt -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
set fid [open wombat.txt w+];&lt;br /&gt;
set capturedinfo $expect_out(buffer);&lt;br /&gt;
puts $fid $capturedinfo;&lt;br /&gt;
set output $expect_out(buffer)&lt;br /&gt;
send &amp;quot;exit\r&amp;quot;&lt;br /&gt;
puts &amp;quot;$output\r\n&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now it just puts what I want in a file called wombat.txt ready for further processing.  &lt;img src=&quot;images/smiles/icon_biggrin.gif&quot; alt=&quot;Very Happy&quot; border=&quot;0&quot; /&gt; &lt;br /&gt;
Probably need to tidy up a bit now, but at least I'm happy again.&lt;br /&gt;
Cheers&lt;br /&gt;
&lt;br /&gt;
Pete</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=103073#103073</comments>
                                        <author>PeterM</author>
                                        <pubDate>Thu Dec 01, 2011 1:26 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=103073#103073</guid>
                                      </item>
                                      <item>
                                        <title>Fun and games with expect</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=103072#103072</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=67177'&gt;PeterM&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Dec 01, 2011 1:07 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Afternoon Max,&lt;br /&gt;
I am also having a big fight with expect but I might be able to help a little. I can get it writing to a file but it puts the wrong thing in. I have put in the lines&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: darkblue&quot;&gt;set fid [open wombat.txt w+];&lt;br /&gt;
set capturedinfo $expect_out(buffer);&lt;br /&gt;
puts $fid $capturedinfo;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Which opens a file called wombat.txt for writing and puts the expect_out buffer into a variable which in turn is written to the file.&lt;br /&gt;
My problem is that it is writing output from a previous step into the file and actually prints out the information I want twice. &lt;br /&gt;
Here's my work-in-progress script&amp;#058;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: darkblue&quot;&gt;#!/usr/bin/expect&lt;br /&gt;
# Usage: gwinfo userid password&lt;br /&gt;
set timeout 10&lt;br /&gt;
set mgwyip [lindex $argv 0]&lt;br /&gt;
set userid [lindex $argv 1]&lt;br /&gt;
set password [lindex $argv 2]&lt;br /&gt;
match_max 100000&lt;br /&gt;
puts &amp;quot;logging in to $mgwyip\r&amp;quot;&lt;br /&gt;
&lt;br /&gt;
spawn ssh $userid@$mgwyip&lt;br /&gt;
expect {&lt;br /&gt;
    -re &amp;quot;continue connect&amp;quot; {send &amp;quot;yes\r&amp;quot;}&lt;br /&gt;
    timeout {puts &amp;quot;Host is known&amp;quot;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
    -re &amp;quot;(P|p)assword: &amp;quot; {send &amp;quot;$password\r&amp;quot;}&lt;br /&gt;
    -re &amp;quot;Warning:&amp;quot; {send &amp;quot;$password\r&amp;quot;}&lt;br /&gt;
    -re &amp;quot;Connection refused&amp;quot; {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    -re &amp;quot;Connection closed&amp;quot;  {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    -re &amp;quot;no address.*&amp;quot; {puts &amp;quot;Host error -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
    timeout {puts &amp;quot;Timeout error. Device down or unreachable? &amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
	-re &amp;quot;super&amp;quot; {send &amp;quot;show image version\r&amp;quot;}&lt;br /&gt;
	timeout {puts &amp;quot;Error reading prompt -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
set fid [open wombat.txt w+];&lt;br /&gt;
set capturedinfo $expect_out(buffer);&lt;br /&gt;
puts $fid $capturedinfo;&lt;br /&gt;
&lt;br /&gt;
expect {&lt;br /&gt;
	-re &amp;quot;super&amp;quot; {send &amp;quot;exit\r&amp;quot;}&lt;br /&gt;
	timeout {puts &amp;quot;Error reading prompt -&amp;gt; $expect_out(buffer)&amp;quot;;exit}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
set output $expect_out(buffer)&lt;br /&gt;
send &amp;quot;exit\r&amp;quot;&lt;br /&gt;
puts &amp;quot;$output\r\n&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It's a bit messy but that's because I keep changing bits, adding bits and removing bits.&lt;br /&gt;
If you get your script to work, could you post the details?&lt;br /&gt;
&lt;br /&gt;
Cheers&lt;br /&gt;
&lt;br /&gt;
Pete</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=103072#103072</comments>
                                        <author>PeterM</author>
                                        <pubDate>Thu Dec 01, 2011 1:07 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=103072#103072</guid>
                                      </item>
                                      <item>
                                        <title>Fun and games with expect</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=102787#102787</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=20905'&gt;maxeaves&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Nov 14, 2011 2:42 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Dear all,&lt;br /&gt;
&lt;br /&gt;
I think this should be an easy answer, but I cannot find out how to do this.&lt;br /&gt;
&lt;br /&gt;
What I have is the following: I want to telnet into a switch, and retrieve the output to a text file.  I'm using expect - so far I have is:&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
expect &amp;lt;&amp;lt; EOF&lt;br /&gt;
&lt;br /&gt;
set timeout 20&lt;br /&gt;
spawn telnet xxx.xxx.xxx.xxx&lt;br /&gt;
expect &amp;quot;telnet@******************&amp;gt;&amp;quot;&lt;br /&gt;
send &amp;quot;en\r&amp;quot;&lt;br /&gt;
expect &amp;quot;Password:&amp;quot;&lt;br /&gt;
send &amp;quot;*******\r&amp;quot;&lt;br /&gt;
expect &amp;quot;*#&amp;quot;&lt;br /&gt;
send &amp;quot;show int brief\r&amp;quot; &lt;br /&gt;
expect &amp;quot;*&amp;quot;&lt;br /&gt;
send &amp;quot;exit\rexit\r&amp;quot;&lt;br /&gt;
exit&lt;br /&gt;
EOF&lt;br /&gt;
&lt;br /&gt;
What I cannot seem to get to work is the output from the SHOW INT BRIEF command to be outputted to a file.....I've tried send &amp;quot;show int brief\r&amp;quot; &amp;gt;&amp;gt; outputfile.txt  but it doesn't seem to like the output.  I've also tried the send_log and file_log options, but this also doesn't do want I want it to do.&lt;br /&gt;
&lt;br /&gt;
Suggestions ?&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Max</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=102787#102787</comments>
                                        <author>maxeaves</author>
                                        <pubDate>Mon Nov 14, 2011 2:42 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=102787#102787</guid>
                                      </item></channel></rss>