[英]expect script inside bash script
我真的很難過! 我不願意使用RSA AUTH。
#!/bin/bash
echo "Enter the server password"
read password
cd /home/mike/
# this is included the code below ->
/usr/bin/expect << EOD
set timeout -1
spawn scp file.txt server.com:/home
expect {
timeout { send_user "TIME OUT\n"; exit 1 }
"*assword: "
}
send "$password\r"
expect {
"s password: " { send_user "\nIncorrect Password. Login Failed.\n"; exit 1 }
"100%"
}
sleep 1
send "exit\r"
expect eof
這可以正常工作,並且file.txt被傳輸到服務器,但我收到此警告消息->
" line 44: warning: here-document at line 22 delimited by end-of-file (wanted `EOD')"
當我在'expect eof'之后最后添加EOD時,出現此錯誤->
send: spawn id exp4 not open
while executing
"send "exit\r"
任何幫助,將不勝感激。 我再次說我不能使用pubkey auth,所以請不要建議。
通過替換最后一行:
expect eof
與:
EOD
我不再抱怨了。 請注意,您的EOD
標記(在初始/usr/bin/expect
行中定義)之前不能有任何選項卡(也可能還有空格?)。
無需嘗試使用expect
編寫腳本,只需使用curl
即可通過scp或sftp將文件復制到遠程主機或從遠程主機復制文件,然后將身份驗證憑據傳遞給curl命令,如下所示:
curl sftp://remotehost.domain.com/path/to/remote/file --user username:password -o /path/to/local/file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.