Skip to content

Commit

Permalink
Add userkill
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed May 27, 2024
1 parent 93a5114 commit 9ec27fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Auto detect text files and perform LF normalization
* text=auto
*.sh text eol=lf
31 changes: 31 additions & 0 deletions userkill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Killing NGINX process as user provided

if [ -z "$USER" ]; then
echo "\$USER is not provided"
exit 1
fi

if [ "$USER" == "root" ]; then
echo "Don't call this on root!"
exit 1
fi

# Get the list of processes for the user
user_procs=$(ps -u $USER --forest -o pid=,comm=)

# Loop through each process
while read -r pid comm; do
# Skip if the command is subcommand or essential features
if [[ "$comm" =~ ^(\\|\|).* || "$comm" == "sh" || "$comm" == "bash" || "$comm" == "docker" || "$comm" == "systemd" ]]; then
continue
fi

# Kill the process
echo "Killing process $pid ($comm)"
pkill -P $pid
kill -9 $pid

done <<< "$user_procs"

0 comments on commit 9ec27fb

Please sign in to comment.