Created
March 11, 2021 11:46
-
-
Save diki-haryadi/fd7a31742dcf13a84e91506b376fd878 to your computer and use it in GitHub Desktop.
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 | |
# file: /usr/local/bin/kill_ports | |
PS3='Please enter your choice: ' | |
options=$(lsof -PiTCP -sTCP:LISTEN | awk '{print $9}' | sed -n '1!p') | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
select port in $options | |
do | |
echo "Selected character: $port" | |
echo "Selected number: $REPLY" | |
var2=$(echo $port | cut -f2 -d:) | |
echo -e "killing ${RED}port $var2 ${NC}!" | |
echo $(lsof -ti tcp:$var2 | xargs kill) | |
exit 0 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment