0

Anyone can help me what will be the problem? login name and password is from .netrc. , < before example.script wont work

  #!/bin/bash
  HOST='192.163.3.3'
  FILE="a.txt"

  while :; do
      ftp -p -v -i $HOST << example.script >> a.log
      grep -qF "Connected" a.log &&
      grep -qF "File successfully transferred" a.log && break
  done

  exit 0

example.script contains

 put $FILE
 quit

And the error is:

 ./example.sh: line 15: syntax error: unexpected end of file

I got this while I'm using sh -vx on my script:

  while :; do
  ftp -p -v -i $HOST < example.script >> a.log
  grep -qF "Connected" a.log &&
  grep -qF "File successfully transferred" a.log && break
  done
  + :
  + ftp -p -v -i 192.163.3.3
  + grep -qF Connected a.log
  grep: a.log: No such file or directory
  + :
  + ftp -p -v -i 192.163.3.3
  + grep -qF Connected a.log
  grep: a.log: No such file or directory
  + :

Note that this code fixes the problem (using < instead of << for the input redirection). The script file is given as exaple.script instead of example.script.

9
  • 3
    It seems you always make the same type of mistakes! You already made the same mistake 2 days ago in the post stackoverflow.com/questions/13600009/ftp-while-do-error Commented Nov 30, 2012 at 18:56
  • if i use < i got error: grep: a.log: No such file or directory grep: a.log: No such file or directory grep Commented Nov 30, 2012 at 18:58
  • Start your script with #!/bin/bash -vx when debugging it. Commented Nov 30, 2012 at 18:59
  • And perhaps you want > a.log 2>&1 and you might want to use ncftp or wget or curl Commented Nov 30, 2012 at 19:01
  • the result is on my 2nd comment Commented Nov 30, 2012 at 19:03

2 Answers 2

2

Change your here document << which has nothing to do here! Instead, you mean:

ftp -p -v -i $HOST < example.script >> a.log
Sign up to request clarification or add additional context in comments.

1 Comment

grep: a.log: No such file or directory grep: a.log: No such file or directory grep: a.log: No such file or directory Another problem :/
0

You need to close your here-doc :

#!/bin/bash
HOST='192.163.3.3'
FILE="a.txt"

while :; do
    ftp -p -v -i $HOST <<EOF example.script >> a.log
    grep -qF "Connected" a.log &&
         grep -qF "File successfully transferred" a.log && break
done
EOF

<< open a here-doc

3 Comments

But then you need to close the while loop too.
dont work :/ ./example.sh: line 14: syntax error: unexpected end of file
That's unlikely to be the solution; it shouldn't have been a here-doc in the first place. << was a typo for <.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.