Note that there are some explanatory texts on larger screens.

plurals
  1. POExpect Output inconsistency
    primarykey
    data
    text
    <p>I want to automate the following interaction using Tcl/expect</p> <pre><code>[root@mgmt NAS]# ssh -q -p 8022 -l user 10.1.1.1 Password: HP Network Automation Version 9.10.02 Type "HELP connect" to see how to connect to a device. Type "HELP" to view a list of available commands. NA&gt;connect 10.1.1.2 WARNING: You do not have an approved reservation for this device at this time. Attempting to connect to device bigip1.network.company.net (10.1.1.2). Last login: Wed Sep 26 08:11:42 2012 from 10.2.1.1 Last login: Wed Sep 26 08:11:42 2012 from 10.2.1.1 [root@bigip1:Standby] config # [root@bigip1:Standby] config # [root@bigip1:Standby] config # [root@bigip1:Standby] config # uname -a Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux [root@bigip1:Standby] config # exit logout Disconnected from device bigip1.network.company.net (10.1.1.2). NA&gt;quit Logging out of the NA Proxy Interface. &lt;Blank Line: couldn't show it with simple formatting&gt; </code></pre> <p>The user input is essentially:</p> <pre><code>password connect 10.1.1.2 uname -a exit quit </code></pre> <p>The script I wrote out, <code>connect.exp</code>, is as follows:</p> <pre><code>#!/usr/local/bin/expect # Set the input parameters set nashost [lindex $argv 0] set port [lindex $argv 1] set user [lindex $argv 2] set passw [lindex $argv 3] set device [lindex $argv 4] set cmd [lindex $argv 5] set binpath /usr/bin log_user 0 # Set timeout to 45 seconds set timeout 45 #check if all were provided if { $nashost == "" || $port == "" || $user == "" || $passw == "" || $device == "" || $cmd == "" } { puts "Usage: &lt;nashost&gt; &lt;port&gt; &lt;user&gt; &lt;passw&gt; &lt;device&gt; &lt;command&gt;\n" exit 1 } # String Variables set nasprompt "NA&gt;$" set prompt "config # $" # Flag Variables set running 1 set count 0 # SSH to specified NAS host if { [catch {spawn $binpath/ssh -q -p $port -o "StrictHostKeyChecking no" -l $user $nashost} error] } { puts "Spawn: SSH failed: $error" exit } expect { "assword: " { send "$passw\r" incr count if {$count &gt; 3} { puts "SSH failed on authentication after 3 tries" set running 0 } else { exp_continue } } -re "$nasprompt" { set running 1 } "Connection refused" { puts "$expect_out(buffer)" set running 0 } "Offending key" { puts "Host key verification failed." set running 0 } eof { puts -nonewline "Connection terminated unexpectedly:\n$expect_out(buffer)" set running 0 } timeout { puts "ssh: connect to NAS host $host: Connection timed out" set running 0 } } if {$running == 1} { send "connect $device\r" expect { -re "$nasprompt" { if {$running &gt; 0} { puts "connect to Device $device failed:\n$expect_out(buffer)" } send "quit\r" } -re "$prompt" { if {$running &gt; 0} { send "$cmd\r" set running 0 exp_continue } else { puts "$expect_out(buffer)" send "exit\r" } } full_buffer { puts "$expect_out(buffer)" exp_continue } eof { puts "ssh: Connection terminated unexpectedly during command execution: $host." } timeout { puts "ssh: Connection timed out during command execution: $host." } } } </code></pre> <p>The issue I face is that the output I get for this interaction with this script is inconsistent.</p> <p>I call the script as follows: <code>expect connect.exp 10.1.1.1 8022 user 'pwd' 10.1.1.2 'uname -a'</code></p> <p>Output one:</p> <pre><code>[root@bigip1:Standby] config # [root@bigip1:Standby] config # uname -a Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux [root@bigip1:Standby] config # </code></pre> <p>Output two:</p> <pre><code>&lt;blank line&gt; &lt;blank line&gt; u[root@bigip1:Standby] config # [root@bigip1:Standby] config # </code></pre> <p>The <code>u</code> at the beginning of line 3 is part of the output, not a typo.</p> <p>Other variations of output two exist as well.</p> <p>The output I expected is: </p> <pre><code>Linux bigip1.network.company.net 2.6.18-164.11.1.el5.1.0.f5app #1 SMP Thu Apr 8 18:26:58 PDT 2010 i686 i686 i386 GNU/Linux [root@bigip1:Standby] config # </code></pre> <p>What am I doing incorrect in my script?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload