# 定义一个函数来处理 SSH 连接 function try_ssh_connection { local server=$1 local user=$2 local password=$3 local label=$4
echo "正在尝试连接到 $server,用户名:$user(连接:$label)" | tee -a $LOG_FILE timeout 30 sshpass -p $password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -tt $user@$server "echo \"Hello from $label\"; date; sleep 10" 2>&1 | tee -a $LOG_FILE result=${PIPESTATUS[0]} if [ $result -eq 124 ]; then echo "错误:$label 连接超时" | tee -a $LOG_FILE elif [ $result -ne 0 ]; then echo "错误:$label 连接失败" | tee -a $LOG_FILE else echo "$label 连接成功!" | tee -a $LOG_FILE fi sleep 3 }