Skip to content

Instantly share code, notes, and snippets.

@DrSnowbird
Last active September 11, 2018 01:43
Show Gist options
  • Save DrSnowbird/99886b7f0894de7726f8e6a467283076 to your computer and use it in GitHub Desktop.
Save DrSnowbird/99886b7f0894de7726f8e6a467283076 to your computer and use it in GitHub Desktop.
Linux Utility - find which process is using a specific port
#!/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