0

I'm a unix novice and a rusty one at that. I'm writing a unix shell script that is using an sftp batch file to copy a bunch of individual files from one server to another. Wildcards will not work in this situation. So my script looks something like this:

#!/bin/bash 

echo "Starting..."

USER="user"
DEST="server"

sftp -b batch.txt $USER@$DEST

echo "Complete."

And my batch file looks something like this:

cd /Data/in
lcd /Data/in

put file1
put file5
put file9
...
bye

As long as all of the files are present in the source directory, this all works fine. My issue is that if any of the 170 or so files are missing from the source directory the whole script will end with a "file not found" error. I'd like it to just keep going, ignoring any "file not found" issues. Is there a quick way to do this? Or am I looking at writing code to check if every file in this list exists before I begin the sftp?

Also, as a side question, would it be better for me to use mput in this situation?

Thanks for any help.

Bobby

Bobby
  • 7
  • 1
  • 4
  • This might be helpful to you http://stackoverflow.com/questions/22009364/is-there-a-try-catch-command-in-bash You need a try catch statement but turns out bash doesnt have it so this post has alternatives to it – let_the_coding_begin Feb 28 '17 at 21:24
  • Thanks for the link, interesting read, but I don't think I can use the || or && in this situation. I don't see it available for use while in an sftp batch scenario. – Bobby Feb 28 '17 at 21:52

0 Answers0