2016-09-25 73 views
0

得到了#!/usr/bin/expect -f#!/bin/bash;現在我得到了錯誤:期望語法錯誤./auto.sh ./auto.sh:第12行:意外令牌附近的語法錯誤}} ./auto.sh:line 12:`}'

./autom.sh: line 7: syntax error near unexpected token `}' 
./autom.sh: line 7: `"*\#" { send "cd /var-tmp"; send "./scmd.sh -tmp /var/tmp -plugins /var/tmp/plugins -dmore \r"; }' 

代碼:

set i 0 
IP_FILE="./hst.txt" 

for i in `cat $IP_FILE`; do 
sapwn ssh "@$i" 
expect { 
"*\#" { send "cd /var-tmp"; send "./scmd.sh -tmp /var/tmp -plugins /var/tmp/plugins -dmore \r"; } 
"*\#" { puts "ejecucion exitosa" } 
} 
EOD 
done>>logfile.txt` 
+1

刪除'#在/ usr/bin中/預期'因爲只有一個bash是必需的 – anubhava

+0

你的問題是令人困惑的格式化;我希望我改進了它。我將'。/ utom.sh'改爲'。/ autom.sh' - 在發佈時名稱如何切換? (另外,標題引用'./ auto.sh',但是body引用'./ autom.sh' - 請保持一致!)你應該修正'spawn'的拼寫(它不是'sapwn')。你有一些'expect'的代碼僞裝成shell腳本;這是導致錯誤。你忘了在線路上的某處運行預期嗎?也許'在'do'之後和'sapwn'或'spawn'之前預期<< EOD'? –

回答

1

相反,固定你怎麼慶典之間和接口的期望,它更容易只是停止使用期望在所有的!

#!/bin/bash 
ip_file=hst.txt 

while read -r ip; do 
    ssh "$ip" 'bash -s' <<'EOF' 
cd /var-tmp || { echo "Could not cd to /var-tmp" >&2; exit 1; } 
./scmd.sh -tmp /var/tmp -plugins /var/tmp/plugins -dmore 
EOF 
done <"$ip_file" >>logfile.txt 
0

這似乎是一個bash腳本其中有想到代碼混了進去。根據錯誤EOD那裏我猜這應該是一個HERE文檔,但你已經失去了實際的期望調用。也許試試這個:

#!/bin/bash 

set i 0 
IP_FILE="./hst.txt" 

for i in `cat $IP_FILE`; do 
expect - <<EOD 
spawn ssh "@$i" 
expect { 
"*\#" { send "cd /var-tmp\r"; send "./scmd.sh -tmp /var/tmp -plugins /var/tmp/plugins -dmore \r"; } 
"*\#" { puts "ejecucion exitosa" } 
} 
EOD 
done>>logfile.txt 

編輯:添加了\r你的第一個cd命令後固定的spawn拼寫。

編輯#2:而且,正如@CharlesDuffy提到的,閱讀for行不是一個好主意。這樣的事情是更好:

#!/bin/bash 

set i 0 
IP_FILE="./hst.txt" 

while read -r i; do 
expect - <<EOD 
sapwn ssh "@$i" 
expect { 
"*\#" { send "cd /var-tmp"; send "./scmd.sh -tmp /var/tmp -plugins /var/tmp/plugins -dmore \r"; } 
"*\#" { puts "ejecucion exitosa" } 
} 
EOD 
done < "$IP_FILE" >> logfile.txt 
相關問題