Skip to content
Snippets Groups Projects
Commit 7c17ad8a authored by Dylan W Wheeler's avatar Dylan W Wheeler
Browse files

Merge branch 'feat-kill-user-process-script' into 'main'

FEAT: adding simple script to kill all of a user's currently running processes

See merge request !159
parents 49c4de33 ca87dd66
Branches main
No related tags found
1 merge request!159FEAT: adding simple script to kill all of a user's currently running processes
Pipeline #14513 passed with stage
in 7 minutes and 26 seconds
#!/bin/bash
force=false
username=''
usage() {
echo "Usage: $0 -u USERNAME to run graceful shutdown of processes"
echo "Usage: $0 -u USERNAME -k to run forced shutdown of processes"
}
if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
while [ $OPTIND -le "$#" ]; do
if getopts k option; then
case $option in
k)
force=true
;;
esac
else
username=("${!OPTIND}")
((OPTIND++))
fi
done
if [ -z "$username" ]; then
usage
exit 1
fi
if [ "$username" = "root" ]; then
echo "Username cannot be root"
exit 1
fi
userId=$(id -u $username)
if [ "$force" = true ]; then
echo "Performing SIGKILL on processes belonging to $username"
pkill -9 -u $userId
else
echo "Performing SIGTERM on processes belonging to $username"
pkill -u $userId
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment