如何自动重试SFTP连接尝试? [英] How do I automatically retry an SFTP connection attempt?
本文介绍了如何自动重试SFTP连接尝试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以选择让Bash重试SFTP连接n次或x秒?无论导致错误的原因(服务器关闭,密码错误等),我都无法找到有关使Shell脚本自动重试的任何信息.
Is there an option to have Bash retry an SFTP connection n number of times or for x seconds? I'm unable to find any info on making a shell script automatically retry, regardless of the cause of error (server is down, bad password, etc).
推荐答案
尝试此操作尝试三遍:
c=0; until sftp user@server; do ((c++)); [[ $c -eq 3 ]] && break; done
长版,并显示错误消息:
Long version with error message:
c=0
until sftp user@server; do
((c++))
if [[ $c -eq 3 ]]; then
echo error
break
fi
done
这篇关于如何自动重试SFTP连接尝试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文