Skip to content

Instantly share code, notes, and snippets.

@harrisoncramer
Last active March 12, 2020 00:32
Show Gist options
  • Save harrisoncramer/08e43614735b37928eff289819387def to your computer and use it in GitHub Desktop.
Save harrisoncramer/08e43614735b37928eff289819387def to your computer and use it in GitHub Desktop.
Killport
#!/bin/bash
if [ $# -eq 0 ]; then
echo 'Must provide ports.'
exit 1
fi
for var in "$@"
do
if [ "$var" -eq "$var" ] 2>/dev/null
then
echo Killing port: $var
lsof -i :${var} | awk 'NR>1 {print $2}' | xargs kill
else
echo "ERROR: $1 is not an integer."
exit 1
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment