Subrato M
Subrato M

Reputation: 169

Script to connect to FTP in a shell

I have to test out some FTP issues and so I was looking at writing this script which will loop through x times, sleep a random number of seconds and continue. I am looking at samples and this is what I came up with but can't get it to run. Any ideas on what is wrong with the script?

#! /bin/bash
HOST='host'
USER='user'
PASSWD='password'

i=1
while [[ $i -le 25 ]]
  do
    echo "$i"
    ftp -n -v $HOST << EOT
    quote USER $USER
    quote PASS $PASSWD
    bye
    x=$(( ($RANDOM % 4) + 1))
    echo "Sleeping $x number of seconds";
    sleep $x
    let i=i+1;
    EOT
  done
exit 0

Upvotes: 1

Views: 931

Answers (1)

codeforester
codeforester

Reputation: 43109

The heredoc end marker EOT is in the wrong place. Correct it like here:

#! /bin/bash
HOST='host'
USER='user'
PASSWD='password'

i=1
while [[ $i -le 25 ]]
  do
    echo "$i"
    ftp -n -v $HOST << EOT
    quote USER $USER
    quote PASS $PASSWD
    bye

EOT

    x=$(( ($RANDOM % 4) + 1))
    echo "Sleeping $x number of seconds"
    sleep $x
    let i=i+1
  done
exit 0

Upvotes: 2

Related Questions