有一个服务器列表,您需要“环” nc(ping 不可用)如何将-w参数设置为毫秒值?
-w timeout
If a connection and stdin are idle
for more than timeout seconds, then
the connection is silently closed.
这是 Ansilbe 的“事实”的一部分,即每个受管节点最多有 10 台服务器要检查(最多 3000 台),每台服务器等待一秒钟将导致 10 x 3000 秒的停机时间。
nc -w不支持毫秒。查看netcat-openbsd 的实现:也就是说,它
-w需要整数秒并将它们转换为毫秒(但代码的其他部分也可能只期望整秒)。根据您想要做什么,您可以使用其他实用程序(例如 socat、nmap)来实现它。
通过超时找到一个包装器(GNU coreutils)
几个测试:
和一个有效的 bash 脚本: