Note that there are some explanatory texts on larger screens.

plurals
  1. POcat a file to remote system using Expect
    primarykey
    data
    text
    <p>I'm trying to write my first expect script which will push new language to a remote file.</p> <p>This is what I have so far that isn't really working:</p> <pre><code>#!/usr/bin/expect set fid1 [open ./hosts.list r] set hosts [read -nonewline $fid1] close $fid1 set banner_cmd "cat &gt; /tmp/new_sshd_banner &lt;&lt; EOF &lt;New Language Goes Here&gt; EOF" send "\n" stty -echo send_user "Enter password for remote sudo: " expect_user -re "(.*)\n" stty echo set pass $expect_out(1,string) send "\n" foreach host [split $hosts "\n"] { eval spawn "/usr/bin/ssh $host" expect { -re "RSA key fingerprint" {send "yes\r"} timeout {puts "Host is known"} } expect "$host" send "sudo mv /etc/file /etc/file.orig" expect "assword" send $pass expect "$host" send "sudo $file_cmd" expect "$host" send "sudo mv /tmp/file /etc/file } </code></pre> <p>When it runs, this is what I see:</p> <pre><code>opensuse @ 15:10 ~/bin&gt; ./fix_file.exp Enter password for remote sudo: spawn /usr/bin/ssh server &lt;New Language Goes Here&gt; Last login: Fri Aug 31 19:52:45 2012 from 10.152.81.105 [user@server ~]$ Host is known sudo cat &gt; /tmp/new_file &lt;&lt; EOF &gt; &gt; &gt; &lt;New Language Goes Here&gt; &gt; &gt; EOFsudo mv /etc/file /etc/filePASSWORD*missing " while executing "send "sudo mv /tmp/file /etc/file " ("foreach" body line 17) invoked from within "foreach host [split $hosts "\n"] { eval spawn "/usr/bin/ssh $host" expect { -re "RSA key fingerprint" {send "yes\r"} timeout {puts "Host i..." (file "./fix_file.exp" line 45) </code></pre> <p>One thing that isn't readily apparent is that it tacks the password obtained from the user into the output of the mv command.</p> <p>Where have I gone wrong with this?</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