I am trying to make a watchdog bash script which has to check if the port is open, based on the exit status, otherwise should start the daemon. Problem is I can't manage to avoid the script outputting any information by redirecting STDOUT and STDERR.
nc -zv 22.214.171.124 55 | grep " open " >/dev/null 2>&1
nc -zv 126.96.36.199 55 | grep " open " 2>&1 >/dev/null
nc -zv 188.8.131.52 55 | grep " open " &>/dev/null
'FQDN_hostname_or_domainname [184.108.40.206] 55 (?) open'
Nevertheless, this combo works with other commands, such as
netstat. Is it something about netcat, or maybe about bash syntax? Please let me know what I am getting wrong.