【问题标题】:Bash Script Here Documents FTPBash 脚本在此处记录 FTP
【发布时间】:2014-03-09 06:11:14
【问题描述】:

我最近在使用 bash 脚本自动化 ftp 进程时发现了“here”语句。

此处文档参考:http://tldp.org/LDP/abs/html/here-docs.html

bash 脚本中的 ftp 进程需要相当长的时间,我特别想在后台运行它,并让 bash 脚本的下一行在 ftp 进程之后继续。我将如何为“此处”文档执行此操作?

FTP sn-p:

    USER="test"
    PASSWD="test"
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    quit
    END_SCRIPT 

例如:

我希望能够做到这一点:

run ftp snippet &
run other shell commands

但我不太确定将&amp;放在哪里

到目前为止我已经尝试过:

尝试1:(我认为这在语法上不正确,不起作用):

function do_ftp() {
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    quit
    END_SCRIPT
}

do_ftp &
//additional commands

尝试 2:

USER="test"
PASSWD="test"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
quit
END_SCRIPT &

尝试 3:

USER="test"
PASSWD="test"
ftp -n $HOST & <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
quit
END_SCRIPT

【问题讨论】:

  • expect怎么样?
  • 您是否考虑过使用wgetcurl 而不是ftp ???

标签: linux bash shell ftp


【解决方案1】:

我还没有在 ftp 上测试过,但是:

我知道当你想在 HEREDOC 上放置变量时你应该做其他事情

例如,我为ssh 命令尝试了以下操作:

while read pass port user ip fileinput fileoutput filetemp; do
     sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p $port $user@$ip fileinput=$fileinput fileoutput=$fileoutput filetemp=$filetemp 'bash -s'<<ENDSSH1
     python /path/to/f.py $fileinput $fileoutput $filetemp
     ENDSSH1
done  <<____HERE1
     PASS    PORT    USER    IP    FILE-INPUT    FILE-OUTPUT    FILE-TEMP
____HERE1

你可能需要这样的东西......

【讨论】:

    猜你喜欢
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多