ibash
ibash

Reputation: 741

Find a process id using netstat in combination with ps

I want to find the process id using netstat and see how long this process has been running by using ps. I currently have two separate commands to do this. How do I do it with one command?

netstat -anp | grep http | grep ESTABLISHED | awk {'print $7}' | awk -F '/' {'print $1'}

and:

ps -eo pid,uid,ruser,etime | grep someuser

Upvotes: 5

Views: 25575

Answers (1)

Suku
Suku

Reputation: 3880

for i in `netstat -anp | grep http | grep ESTABLISHED | awk {'print $7}' | awk -F '/' {'print $1'} | uniq` ; do ps -eo pid,uid,ruser,etime | grep $i ; done

Upvotes: 14

Related Questions