[英]SFTP Upload using Bash
我有一個腳本程序,它使用 Bash 和 Expect。 這個 shell 腳本正在執行 SFTP 上傳。
這是腳本。
#!/usr/bin/expect -f
/usr/bin/expect << EOD
spawn sftp $loginid@server
#expect "*Are you sure you want to continue connecting*" {send "yes\r" }
expect "Password:*"
send $pwd\r
expect "sftp> "
send "lcd $locdirectory\r"
expect "sftp> "
send "cd $remDirect\r"
expect "sftp> "
send "put $file\r"
expect "sftp> "
send "bye\r"
expect EOD
運行此腳本時,它將在 bye 語句后無限循環。
它不斷在終端上打印“Y”並且永不結束。
請提出為什么會這樣。
如果您使用#!/usr/bin/expect
那么您沒有 bash 腳本:刪除該行
/usr/bin/expect << EOD
然后接受@whjm 的建議
另外,有條件地期望“繼續”的方式? 是
expect {
"*Are you sure you want to continue connecting*" {
send "yes\r"
exp_continue
}
"Password:*" {send $pwd\r}
}
我能夠解決這個問題。 我不得不從腳本中取消注釋以下行。
#expect "*Are you sure you want to continue connecting*" {send "yes\r" }
我的服務器沒有目標服務器的密鑰,所以不是提示輸入密碼而是提示“您確定要繼續連接嗎”? 並且沒有任何適當的通過。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.