Bash Script Expo #2
Posted by they4kman on Wednesday, July 1, 2009 at 10:47 a.m. (1 year ago)

This little bit here prints out the process ID and process name of the process with the specified open port.
#!/bin/bash
ps -p `netstat -pantu | awk "\\$4 ~ /$1$/ { split(\\$NF,pid,\"/\"); print pid[1]; }"` -o comm= -o pid= 2> /dev/null
`netstat -pantu` prints the open ports using the UDP or TCP protocol and the process IDs of the processes that opened the ports. The awk line parses netstat so that it prints only the process ID. Then the ps line prints out the process name and PID. The ending 2> /dev/null stops ps from printing out its help text when there is no process with the specified open port.
The warning that appears above explains that one must `sudo` to see all the processes.
However, if you'd like to just know the PID of the process with the open port, remove the ps, like so:
#!/bin/bash
netstat -pantu | awk "\\$4 ~ /$1$/ { split(\\$NF,pid,\"/\"); print pid[1]; }"
Then you could do this:

Comments
Re: Bash Script Expo #2
Posted by evening dresses on Wednesday, June 16, 2010 at 5:53 a.m. (1 month, 2 weeks ago)
Evening dresses
With more 1000 Designer dresses,we supply Evening Dresses,Custom Dresses,formal gowns,cocktail dresses with wholesale price
prom dresses
Dresses, evening, cocktail, prom dresses, formal gowns from dresseslife. Homecoming dresses and bridesmaid
Graduation Dresses
Looking For discount Balenciaga handbags? The store online sells the Balenciaga bags.
Welcome to visit and buy Balenciaga handbags. we offer Balenciaga Handbags,Balenciaga
Balenciaga Handbags
Balenciaga
Balenciaga sale
Re: Bash Script Expo #2
Posted by write my thesis on Sunday, June 6, 2010 at 7:49 p.m. (1 month, 3 weeks ago)
well, your tutorial teaches me a lot, so thanks for sharing it with us