Created
May 10, 2021 02:40
-
-
Save pacozaa/f53a3a6a21b8266591b3291bd55723e3 to your computer and use it in GitHub Desktop.
findAndKillPort.sh
This file contains hidden or 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 | |
read -p "Enter port number(ex. 7070): " PORT_NUMBER | |
echo "Here is $PORT_NUMBER" | |
if [ "$PORT_NUMBER" = "" ]; then | |
echo "No port number to target" | |
exit 0 | |
fi | |
echo "Finding $PORT_NUMBER .... PID" | |
PID_FINDING=$(sudo lsof -iTCP -sTCP:LISTEN -n -P | grep $PORT_NUMBER) | |
echo $PID_FINDING | |
read -p "What's PID do you want to kill?: " PID_TARGET | |
if [ "$PID_TARGET" = "" ]; then | |
echo "No PID to target" | |
exit 0 | |
else | |
echo "Killing $PID_TARGET" | |
kill -9 $PID_TARGET | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment