pathScripts/murder

25 lines
599 B
Text
Raw Permalink Normal View History

#!/bin/bash
# Check if an argument is given
if [ $# -eq 0 ]; then
echo "Usage: murder [process name or port]"
exit 1
fi
# Get the input parameter
ARGUMENT=$1
# Check if the argument is numeric
if [[ $ARGUMENT =~ ^[0-9]+$ ]]; then
echo "Killing processes listening on port $ARGUMENT"
lsof -t -i:$ARGUMENT | xargs kill
else
# Process name was given instead of a port number
echo "Killing processes with name $ARGUMENT"
for PID in $(ps aux | grep $ARGUMENT | grep -v grep | awk '{print $2}'); do
echo "Killing process $PID"
sudo kill -9 $PID
done
fi