我有一個將檔案從 linux 服務器傳輸到 windows 服務器的腳本。我想記錄與傳輸相關的資料,但 EOF 在 HEREDOC 構造中給了我錯誤。誰能告訴我前進的道路。
我的腳本是:
#!/usr/bin/expect
spawn sftp XXXX@XXXXXX <<EOF>> log.file
expect "password:"
send "ABC\n"
expect "sftp>"
send "cd /FIRST\r"
expect "sftp>"
send "lcd /home\r"
expect "sftp>"
send "mput /home/*First*\r"
send "bye\r"
interact
uj5u.com熱心網友回復:
改用shell腳本并呼叫expect傳遞給它的“-”以使其從其標準輸入中讀取,這將是HEREDOC(即<<EOF ... EOF):
#!/bin/sh
/usr/bin/expect - <<EOF >> /tmp/log
spawn sftp XXXX@XXXXXX
expect "password:"
send "ABC\n"
expect "sftp>"
send "cd /FIRST\r"
expect "sftp>"
send "lcd /home\r"
expect "sftp>"
send "mput /home/*First*\r"
send "bye\r"
EOF
uj5u.com熱心網友回復:
或者
#!/usr/bin/expect
log_file -a log.file
spawn sftp XXXX@XXXXXX
# ... the rest is all the same.
如果您實際上并未(作為人類)與 sftp 行程進行互動,則可以將其用作最后一行
expect eof
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/388694.html
下一篇:帶反斜杠的字串到字典
