I have a bash program that checks that a daemon in a given port is working:
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:
$ 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?