Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sftp avoid exit when file is not found

Tags:

bash

sftp

I have this script:

filePattern='sor.log*'
filePattern2='sor.SOR.log*'
myLocation=/opt/tradertools/omer
clientLocation=/opt/tradertools/omer/sor/from
clientName=vmonitorlmpa
clientUser=root
clientPass=triltest

export SSHPASS=$clientPass

sshpass -e sftp -oStrictHostKeyChecking=no -oBatchMode=no -b - $clientUser@$clientName << !

    get $clientLocation/$filePattern2 $myLocation
    get $clientLocation/$filePattern $myLocation

   bye
!

But if filepattern2 isn't found, it will exit. How do I avoid using two SFTP connections?

like image 389
mike Avatar asked Aug 05 '15 10:08

mike


1 Answers

Quoting the sftp man page:

sftp will abort if any of the following commands fail: get, put, reget, reput, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd, df, symlink, and lmkdir.

Termination on error can be suppressed on a command by command basis by prefixing the command with a - character (for example, -rm /tmp/blah*).

So use:

-get $clientLocation/$filePattern2 $myLocation
like image 162
Martin Prikryl Avatar answered Nov 14 '22 23:11

Martin Prikryl