I'm having trouble removing the output from the netstat command when I check if a current port is being used. I dont need the output of the command but rather just the error code.
Running netstat -anp | grep 1521 &>/dev/null
results in
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
being shown as the output. I have also tried:
2>/dev/null| cut -d' ' -f45-50 | sed 's/[^0-9]*//g'
which just results in a bunch of empty lines after the Not all processes... output but still displays that in the output.
ended up solving my own problem. Use the following
netstat -taepn 2>/dev/null | grep -Po "\b(\d|\.)+:1521\b" 1>/dev/null
This is specific for my situation when I just want the error code and no output