Skip to content

Instantly share code, notes, and snippets.

@ron4stoppable
Created December 22, 2021 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ron4stoppable/234a7dd60dd829c1aa82611364442d37 to your computer and use it in GitHub Desktop.
Save ron4stoppable/234a7dd60dd829c1aa82611364442d37 to your computer and use it in GitHub Desktop.
A script to clear any running process on given port number
#!/bin/bash
touch 34_temp.text
lsof -n -i4TCP:$1 | awk '{print $2}' > 34_temp.text
pidToStop=`(sed '2q;d' 34_temp.text)`
> 34_temp.text
if [[ -n $pidToStop ]]
then
kill -9 $pidToStop
echo "Port $1 is now clear."
else
echo "Sorry nothing running on above port"
fi
rm 34_temp.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment