作者:八卦男1002_426 | 来源:互联网 | 2023-09-02 10:28
Ihaveabashprogramthatchecksthatadaemoninagivenportisworking:我有一个bash程序,它检查给定端口中的守护进程
I have a bash program that checks that a daemon in a given port is working:
我有一个bash程序,它检查给定端口中的守护进程是否正常工作:
nc -z localhost $port > /dev/null
if [ "$?" != "0" ]
then
echo The server on port $port is not working
exit
fi
This program works perfectly in CentOS 6. However, it seems that CentOS 7 has changed the underlying implementation for nc
command (CentOS 6 seems to use Netcat and CentOS 7 uses another thing called Ncat) and now the -z
switch doesn't work:
这个程序在CentOS 6中非常好用。然而,CentOS 7似乎已经改变了nc命令的底层实现(CentOS 6似乎使用Netcat和CentOS 7使用另一种叫做Ncat的东西),而现在-z开关不起作用:
$ nc -z localhost 8080
nc: invalid option -- 'z'
Looking to the man nc
page in CentOS 7 I don't see any clear alternative to -z
. Any suggestion on how I should fix my bash program to make it work in CentOS 7?
在CentOS 7的男子nc页面上,我没有看到任何明显的替代-z。关于如何修改bash程序以使其在CentOS 7中工作的任何建议?
3 个解决方案