I have a script which connects to a remote server via SFTP and get some file from there. My script goes like this:
/usr/bin/sftp USER@remote.server.com <<EOF lcd /dir1/dir2/dir3 cd /rsdir1/rsdir2/rsdir3 get file_pattern`date -d "last month" +%m%Y`.csv EOF rc=$? if [[ $rc != 0 ]] then echo "Error occured getting file and the script abended with error code $rc" `date "+%Y-%m-%d-%H.%M.%S"` exit 1 else echo "Successfully transferred the file" `date "+%Y-%m-%d-%H.%M.%S"` fi
However, even if the script doesn't find the file with the pattern it goes to the else part of the script and gives me the output on the screen as
Connecting to remote.server.com... sftp> lcd /dir1/dir2/dir3 sftp> cd /rsdir1/rsdir2/rsdir3 sftp> get file_pattern032014.csv Couldn't stat remote file: No such file or directory File "/rsdir1/rsdir2/rsdir3/file_pattern032014.csv" not found. Successfully transferred the file YYYY-MM-DD-24HH.MI.SS
Any advices on what I might be doing wrong here?