Created
April 25, 2020 03:39
-
-
Save eftakhairul/784a060aec4fe262212436ea042e6a2d to your computer and use it in GitHub Desktop.
killport tool
This file contains 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 | |
# Kill process on requested port | |
# Author: Md Eftakhairul Islam | |
if [[ $# -eq 0 ]]; then | |
echo "Port is not specified" | |
exit 1 | |
fi | |
# get the port | |
port=$1 | |
# get the process id | |
process_id=$(lsof -i :"${port}" | awk '{ print $2; }' | head -n 2 | grep -v PID) | |
if [[ process_id -gt 0 ]]; then | |
kill -9 $process_id | |
echo "Process: ${process_id} killed running on port ${port}" | |
else | |
echo "Sorry! No process found running on port ${port}" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment