博文背景
实现SSH的自动重连,比如机器正在开机或者网速慢,可以自行不断尝试,直至成功连接。
具体操作
index=0;
for ((i=1;i<=10;i++));
do sshpass -p xxxxxxx ssh -o PreferredAuthentications=password -o StrictHostKeyChecking=no -o ConnectTimeout=3 root@hangzhou.liuwenwen.net 'echo';
if [[ $? -eq 0 ]];
then
index=1;
break;
fi;
done;
if [[ "$index" -eq 1 ]];
then sshpass -p xxxxxxx ssh -o PreferredAuthentications=password -o StrictHostKeyChecking=no -o ConnectTimeout=3 root@hangzhou.liuwenwen.net;
fi