'send'不会导致命令在shell中成功执行

时间:2014-10-22 15:14:37

标签: shell tcl expect spawn

考虑以下情况:

#! /usr/bin/expect --

#start of the script

proc A {host_ip} {
    global spawn_id
    spawn ssh $host_ip
}

#pattern match using expect statements on the
#output of the spawned ssh process in A
proc B {} {
   expect -ex "$" { send "ls -l\r"; puts "did get this far" } #<------- (1)
   expect -ex "$" { } #<------- (2)
   #find a filename of interest from the output of 'ls' command earlier
   regexp "((a-b\\S+\\s+)+)" $expect_out(buffer) matched file_of_interest  #<------- (3)

   #the following reliably succeeds in sending the intended command, but is obviously pointless
   expect {
        -ex "$" { send "ls -l\r"; exp_continue} #<------- (4)
   }
}

#call the routines
A $some_ip
B

#end of the script

我的主要问题是在(1)'send'不会导致'ls'命令被发送,或者至少我没有看到任何证据表明它被发送,但'puts'语句仍然被执行。在(1)的'send'之后的'puts'语句仅用于调试目的。在(2)我匹配提示,希望expect_out(缓冲区)将包含'ls'命令的输出。我不明白为什么(4)成功发送命令,但(1)没有,通常,expect_out(缓冲区)不包含所需的数据。

(1)的'send'命令应该有效,但事实并非如此。 (4)的“发送”有效,但没有意义。有没有办法找出为什么(1)的'发送'不成功?关于提高“发送”可靠性的任何建议1.

感谢。

0 个答案:

没有答案
相关问题