Created
December 22, 2021 16:49
-
-
Save ron4stoppable/234a7dd60dd829c1aa82611364442d37 to your computer and use it in GitHub Desktop.
A script to clear any running process on given port number
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 | |
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