在脚本继续之前,我需要在bash脚本中检查远程服务器上的端口。 我在这里和在互联网上搜索,但我无法找到适合我的答案。在bash脚本中检查远程端口状态
我正在使用RHEL 7.2虚拟机,所以我没有-z
参数nc
命令或/dev/tcp/
的事情。 也nc remote.host.com 1284 < /dev/null
鸵鸟政策工作,因为每次我得到退出代码1.
基本上我需要类似的东西:
/bin/someting host port
if [ $? -eq 0 ]; then
echo "Great, remote port is ready."
else
exit 1
fi
对于它的价值,'NC host.com 1234开发/ null'对我来说工作正常。它根据连接状态返回“0”或“1”。你有'nmap'吗?怎么样'nmap --open -p | grep -q“打开”'? –
eddiem
使用RHEL7可以使用/ dev/tcp。用'ls'命令不可见。 – Cyrus
@Cyrus:我鸵鸟政策工作: '$ /dev/tcp/google.com/80 -bash:/dev/tcp/google.com/80:没有这样的文件或directory' @eddiem : 'nc remote_server 1313 dev/null; echo $? Ncat:由对等方重置连接。 1' 'nc remote_server 1477 dev/null; echo $? Ncat:连接超时。 1' – Rohlik