2013-07-12 26 views
1

我發送awk命令通過期望發送,當我發送我得到錯誤,但我不能讀取1沒有這樣的變量使用AWK期望發送獲取無法讀取「1」:沒有這樣的變量錯誤

我沒有使用{{}} mechansim但我沒有工作,

expect "$prompt" { 
    send "awk {{print $1}} /mytest/test.log\r" 
} 

我試着用eascapse序列\,但我因此未找到任何響應expect_out(緩衝),..等等

expect "$prompt" { 
    send "awk '{print \$1}' /mytest/test.log\r" 
} 

我用exec命令也嘗試過

expect "$prompt" { 
    send "exec awk {{print $1}} /mytest/test.log\r" 
} 

回答

4

您必須使用大括號來避免替換。或者,你必須擺脫美元符號和花括號。

幾個例子:


1.在本地計算機上的程序進行交互:

#!/usr/bin/expect -d 

spawn "/bin/bash" 
set cmd "awk '\{print \$1\}' /mytest/test.log\r" 
send $cmd 
expect eof 
puts $expect_out(buffer) 


2.遠程程序通過SSH進行交互:

#!/usr/bin/expect -d 

append cmd {awk '{print $1}' /mytest/test.log} "\r" 
spawn ssh [email protected] 
set prompt ":|#|\\\$" 
interact -o -nobuffer -re $prompt return 
send "mypassword\r" 
interact -o -nobuffer -re $prompt return 
send $cmd 
send "exit\r" 
expect eof 
puts $expect_out(buffer)