Skip to content

Instantly share code, notes, and snippets.

@diki-haryadi
Created March 11, 2021 11:46
Show Gist options
  • Save diki-haryadi/fd7a31742dcf13a84e91506b376fd878 to your computer and use it in GitHub Desktop.
Save diki-haryadi/fd7a31742dcf13a84e91506b376fd878 to your computer and use it in GitHub Desktop.
#!/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