Skip to content
Snippets Groups Projects
Commit 258fcfee authored by Dylan Wheeler's avatar Dylan Wheeler
Browse files

feat: adding flag for force kill and adding check to ensure script is run as root

parent dd41dc2a
No related branches found
No related tags found
1 merge request!159FEAT: adding simple script to kill all of a user's currently running processes
...@@ -3,9 +3,16 @@ ...@@ -3,9 +3,16 @@
username="$1" username="$1"
usage() { usage() {
echo "Usage: $0 USERNAME" echo "Usage: $0 USERNAME to run graceful shutdown of processes"
echo "Usage: $0 USERNAME -k to run forced shutdown of processes"
} }
if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root!"
exit 1
fi
if [ -z "$username" ]; then if [ -z "$username" ]; then
usage usage
exit 1 exit 1
...@@ -18,5 +25,12 @@ if [ "$username" = "root" ]; then ...@@ -18,5 +25,12 @@ if [ "$username" = "root" ]; then
exit 1 exit 1
fi fi
pkill -u $userId if [ -k ]; then
pkill -9 -u $userId 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