I have the following bash script

the SFTP works fine but the echo "Backup done" dosnt work

#!/bin/sh
sftp -b /dev/stdin server <<EOF
  cd /shares/backup/webserver/
  put $bu_PATH$BACKUP_FILE
  quit
  EOF

echo "Backup done"

Can any one help?

link|improve this question
even with a semicolon after last EOF? – mailq Aug 8 '11 at 19:53
@mailq - yup even with that – Rob Aug 8 '11 at 19:54
feedback

3 Answers

up vote 4 down vote accepted

EOF is not at the beginning of the line. Changing your script to:

#!/bin/sh
sftp -b /dev/stdin server <<EOF
  cd /shares/backup/webserver/
  put $bu_PATH$BACKUP_FILE
  quit
EOF

echo "Backup done"

should make it work.

You might replace /dev/stdin server by - as the latter means stdin.

link|improve this answer
feedback

That should be a lower-case "echo" instead of "Echo".

link|improve this answer
well said - thats a typo in the question – Rob Aug 8 '11 at 19:44
feedback

You might be able to improve the process a bit by just echoing the long string to the command. You would eliminate the hanging file created to hold those few lines:

 #! /bin/sh
 echo "cd /shares/backup/webserver/
 put $bu_PATH$BACKUP_FILE
 quit" | sftp -b - server

 if test $? -ne 0
 then
      echo Backup Problem
      exit 1
 fi

 echo 'Backup DONE!'

 exit 0

Notice that the echo line continues over the CR's until another matching quote is discovered.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.