sftp避免在找不到文件时退出 [英] sftp avoid exit when file is not found

查看:84
本文介绍了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连接?

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

推荐答案

引用 sftp手册页:

Quoting the sftp man page:

如果以下任何命令失败,

sftp将中止:getputregetreputrenamelnrmmkdirlslchdirchmodchownchgrplpwddfsymlinklmkdir.可以在命令的基础上通过在命令前面加上-字符(例如,-rm /tmp/blah*)来抑制错误终止.

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

这篇关于sftp避免在找不到文件时退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆