1

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
Subrato M
  • 159
  • 1
  • 12
  • Possible duplicate of [here-document delimited by end-of-file](http://stackoverflow.com/questions/18660798/here-document-delimited-by-end-of-file) – tripleee Feb 08 '17 at 06:00

1 Answers1

2

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
codeforester
  • 39,467
  • 16
  • 112
  • 140
  • 1
    You might want to check [the Stack Overflow `bash` tag wiki](http://stackoverflow.com/tags/bash/info) for recurring questions before posting answers to common ones. Nominating as a duplicate helps focus effort on one question and one canonical set of well-researched, debugged answers, often with coverage of multiple aspects and solution techniques. And thanks for your contributions so far! – tripleee Feb 08 '17 at 06:01
  • 1
    Agreed @tripleee. I will keep that in mind. I am relatively new to SO. – codeforester Feb 08 '17 at 06:32
  • @codeforester thank you for the answer. that helped. – Subrato M Feb 08 '17 at 15:55