bash - 找不到文件时sftp避免退出

标签 bash sftp

我有这个脚本:

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
!

但如果未找到 filepattern2,它将退出。如何避免使用两个 SFTP 连接?

最佳答案

引用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*).

所以使用:

-get $clientLocation/$filePattern2 $myLocation

关于bash - 找不到文件时sftp避免退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31829356/

相关文章:

sql-server - SQL Server 执行 xp_cmdshell 通过 FTP 协议(protocol)从 UNIX 机器导入文本文件

bash - Makefile 通过 make 命令将附加参数传递给 targets 命令

linux - 将文件上传到 sftp 的 bash 脚本

regex - grep 的管道不适用于尾部?

regex - 使用 sed 删除非字母数字字符

java - SFTP 到 FTP 桥

java - 使用 JSch SFTP 客户端连接到 FileZilla 服务器时出错

linux - 当 Linux 中的 sftp 语句之一失败时,sftp 脚本失败

arrays - 错误的数组下标

Bash 写入文件没有 echo ?