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 1.2.3.4 55 | grep " open " >/dev/null 2>&1
or
nc -zv 1.2.3.4 55 | grep " open " 2>&1 >/dev/null
or
nc -zv 1.2.3.4 55 | grep " open " &>/dev/null
returns anyway
'FQDN_hostname_or_domainname [1.2.3.4] 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.