加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 21:18:39 所属栏目:安全 来源:网络整理
导读:我有这个脚本: filePattern='sor.log*'filePattern2='sor.SOR.log*'myLocation=/opt/tradertools/omerclientLocation=/opt/tradertools/omer/sor/fromclientName=vmonitorlmpaclientUser=rootclientPass=triltestexport SSHPASS=$clientPasssshpass -e 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读