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 188.8.131.52 55 | grep " open " >/dev/null 2>&1
nc -zv 184.108.40.206 55 | grep " open " 2>&1 >/dev/null
nc -zv 220.127.116.11 55 | grep " open " &>/dev/null
'FQDN_hostname_or_domainname [18.104.22.168] 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.