I am using nc command in my Linux box like below to check if a port is listening;
This displays success message:
nc -z 192.168.0.2 9000
This displays 0:
echo $?
I have combined it in a shell script .sh file like below;
#!/bin/sh
nc -z 192.168.0.2 9000
echo $?
This displays 1 instead of expected 0. Again, if I modify my script like below, it works;
#!/bin/sh
echo nc -z 192.168.0.2 9000
echo $?
But here the problem is, it displays success message on one like, then displays 0 in next line. I don't want success message, and I am expecting 0. What is wrong here and how can I fix this?
 
     
     
    