2014-01-28 104 views
1

我有一個期望腳本在我的Tcl 8.5框架中。 它被用於產生一個sshUbuntu 11.10到其他Fedora發佈15(Lovelock)個人電腦。用Expect和ssh發送長命令

我管理登錄成功通過期待
另外,我發出的短命令正在被我的腳本成功識別,例如, ifconfig

但隨着exp_send長命令,
他們正在被與每一個X字符之間注入爲「\ r」(空間CR)的expect命令讀發出時。

例如,參數exp_send是(使用exp_internal 1有效):

sudo tshark -c 1 -i ethernet0 -f 'broadcast and ether host 00:00:00:00:00:00' -T fields -E header=y -E separator=, -E quote=d -e frame.time_epoch -e wlan.sa -e wlan_mgt.supported_rates -e wlan_mgt.extented_supported_rates\r 

發送此之後,expect命令讀取它爲:

sudo tshark -c 1 -i ethernet0 -f 'broadcast and ether host 
00:00:00:00:00:00' -T fields -E header=y -E separator=, -E quote=d -e frame.tim 
e_epoch -e wlan.sa -e wlan_mgt.supported_rates -e wlan_mgt.extented_supported_ra 
tes 

(在注意額外的單個空格前3行結束)
如何在不向內部注入「\ r」的情況下發送命令?


編輯#1(2014 1月29日08:30 UTC):
另一個命令也會發生此問題,像echo
例如,我曾與exp_send發送的字符串:

Hello World0!Hello World1!Hello World2!Hello World3!Hello World4!Hello World5!Hello World6!Hello World7!Hello World8!Hello World9!Hello World10!Hello World11!Hello World12!Hello World13!Hello World14!Hello World15!Hello World16!Hello World17!Hello World18!Hello World19!'\r 

而且expect與之間注入 '\ r' 讀它,例如:

echo 'Hello World0!Hello World1!Hello World2!Hello World3! \rHello World4!Hello World5!Hello W 

你可以看到下面的活生生的例子,使用exp_internal 1接收:

expect: does "\u001b]0;[email protected]:~\u0007[[email protected] ~]# " (spawn_id exp9) match full buffer full_buffer? no 
".+"? (No Gate, RE only) gate=yes re=yes 
expect: set expect_out(0,string) "\u001b]0;[email protected]:~\u0007[[email protected] ~]# " 
expect: set expect_out(spawn_id) "exp9" 
expect: set expect_out(buffer) "\u001b]0;[email protected]:~\u0007[[email protected] ~]# " 
send: sending "echo 'Hello World0!Hello World1!Hello World2!Hello World3!Hello World4!Hello World5!Hello World6!Hello World7!Hello World8!Hello World9!Hello World10!Hello World11!Hello World12!Hello World13!Hello World14!Hello World15!Hello World16!Hello World17!Hello World18!Hello World19!'\r" to { exp9 } 
Gate keeper glob pattern for '.+' is ''. Not usable, disabling the performance booster. 
expect: does "" (spawn_id exp9) match full buffer full_buffer? no 
".+"? (No Gate, RE only) gate=yes re=no 
expect: does "echo 'Hello World0!Hello World1!Hello World2!Hello World3! \rHello World4!Hello World5!Hello W" (spawn_id exp9) match full buffer full_buffer? no 
".+"? (No Gate, RE only) gate=yes re=yes 
expect: set expect_out(0,string) "echo 'Hello World0!Hello World1!Hello World2!Hello World3! \rHello World4!Hello World5!Hello W" 
expect: set expect_out(spawn_id) "exp9" 
expect: set expect_out(buffer) "echo 'Hello World0!Hello World1!Hello World2!Hello World3! \rHello World4!Hello World5!Hello W" 
Gate keeper glob pattern for '.+' is ''. Not usable, disabling the performance booster. 

This is basically my Tcl8.5 code(修改後用於可讀性)。

+0

你確定這就是它是如何發送的,還是它只是顯示方式?打開標記('exp_internal 1')來回答這個問題。 –

+0

@glennjackman:的確,我是正面的,已經用'exp_internal 1'驗證過了...... – Dor

+0

這是否與其他長命令一樣?你可以用'echo'做一個測試嗎? –

回答

0

這應有助於:

send "tshark -c 1 -i ethernet0\\\r" 
send " -f 'broadcast and ether\\\r" 
send " host 00:00:00:00:00:00'\\\r" 
send " -T fields -E header=y -\\\r" 
send "E separator=, -E quote=d\\\r" 
send " -e frame.time_epoch -e \\\r" 
send "wlan.sa -e wlan_mgt.supp\\\r" 
send "orted_rates -e wlan_mgt.\\\r" 
send "extented_supported_rates\r" 
+0

嗨。我正在尋找一種無意的注入'\ r'的方法。謝謝! – Dor