Last active
September 11, 2018 01:43
-
-
Save DrSnowbird/99886b7f0894de7726f8e6a467283076 to your computer and use it in GitHub Desktop.
Linux Utility - find which process is using a specific port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### ------------------------- Use ---------------------------- | |
#### To find our what PID/Process is binding to a specific port | |
#### ---------------------------------------------------------- | |
if [ $# -lt 1 ]; then | |
echo "Usage: $0 <port-to-search-process>" | |
exit 1 | |
fi | |
_port=${1} | |
echo "---- Port info ----" | |
sudo netstat -antup|grep ":$_port" | |
echo "---- PID info ----" | |
for _pid in `sudo netstat -antup|grep ":$_port"|awk '{print $6}'|cut -d'/' -f1`; do | |
ps -elf | grep $_pid |grep -v grep | |
done | |
echo | |
#### Background | |
#ps -elf | grep "$(sudo netstat -antup|grep "::2979"|awk '{print $6}'|cut -d'/' -f1)" | |
#ps -elf | grep "$(sudo netstat -antup|grep "::$_port"|awk '{print $6}'|cut -d'/' -f1)" | |
#ps -aux | grep "$(sudo netstat -antup|grep "::$_port"|awk '{print $6}'|cut -d'/' -f1)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment