Remove netstat output (specifically Not all processes could be identified line)

14,582

Solution 1

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

Solution 2

The accepted answer doesn't work for me, CentOS6.5 32bit here. It outputs nothing no matter what state the port is.

I found my solution:

netstat -antp 2>/dev/null | grep [port-num]

This will omit the first two lines of netstat if it is executed by regular user.

The warning two lines needed to be omitted:

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)

and works for two situations:

  1. the port is "LISTEN" state
  2. the port is "TIME_WAIT" state.

Solution 3

Instead of

netstat -anp

you may check using

sudo netstat -anp 

This worked for me.

Share:
14,582

Related videos on Youtube

Zee
Author by

Zee

I usually write code in scala/java/python and I write bash scripts.

Updated on May 25, 2022

Comments

  • Zee
    Zee almost 2 years

    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.

  • Zee
    Zee almost 7 years
    in my case I only wanted the error code and not necessarily any output but Im glad you were able to solve your issue with removing the first two lines!
  • CodyChan
    CodyChan almost 7 years
    @Zee Maybe we are using different platforms, so your answer works for your platform, and my solution works for my platform, which is CentOS6.5-32bit.
  • Carmine Tambascia
    Carmine Tambascia over 4 years
    I would like to add here that this message is seen also when there is an environment variable that cannot be found. For example in those case when you test and create a shell variable and in the next shell session that password is lost.