find open ports and safely kill them — #bash utility for @21 developers

Added this simple bash script to two1helpers on Github:

It lists processes running on an open port and prompts to be sure that you want to safely kill them.  This is useful when you are repeatedly opening and closing ports as part of developing 21 server applications.

# usage ./ $1
echo "searching for processes listening on $PORT_NUMBER which are"
lsof -i tcp:${PORT_NUMBER} | xargs -d\n
read -r -p "Are you sure you want to kill these? [y/N] " response
case $response in
        lsof +c14 -i tcp:${PORT_NUMBER} | awk 'NR!=1 {print $2}' | xargs kill
        echo "ok, never mind!"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s