user1431282
user1431282

Reputation: 6835

Bash Script Here Documents FTP

I recently discovered "here" statements while working with a bash script for automating an ftp process.

Reference for Here Documents: http://tldp.org/LDP/abs/html/here-docs.html

The ftp process takes fairly long in the bash script, and I wanted specifically to run it in the background and have the next line of the bash script continue after the ftp process. How would I do this for "here" documents?

FTP snippet:

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

For example:

I want to be able to do this:

run ftp snippet &
run other shell commands

but I'm not quite sure where to put the &

I have tried so far:

Attempt 1: (I believe that this is syntactically incorrect and does not work):

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

do_ftp &
//additional commands

Attempt 2:

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

Attempt 3 :

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

Upvotes: 1

Views: 613

Answers (1)

MLSC
MLSC

Reputation: 5972

I haven't tested it on ftp BUT:

I know when you want to put variables on HEREDOC you should do something else

For example I tried the following for ssh command:

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

May be something like this is needed by you...

Upvotes: 1

Related Questions