Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要创建一个脚本,将 4 个不同的服务器一一连接,并检查服务器是否正在运行,然后执行命令并退出。如果第一台服务器未运行,则连接到第二台并退出。
我正在考虑使用基于密钥的身份验证通过 SSH 脚本进行连接。
请帮忙。
关于什么
hosts="host1 host2 host3" for h in $hosts; do ssh -o BatchMode=yes -o ConnectTimeout=7 $h command [ $? -eq 0 ] && break done