Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|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
add comment

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.

share|improve this answer
add comment

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

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

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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