I am trying to write shell script to test if a server is able to reach a specified ip and port.
The commands i am using: ncat -w 5 <IP> 636 or 389 > /dev/null 2>&1 < /dev/null | echo $?
The issue is when i check for an exit code for the above two ports i receive a 1.
When i run it without the /dev/null I get an connected to ip.
ncat -v -w 5 <IP> 636
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to <IP>:636.
^C
The issue is if i use the second command without /dev/null, i need to manually cancel the command using: CTRL + C
Any suggestions on how can i test the ip and ldap port using ncat or nc?