From bf47fbc1eb903faf9b77303c2867f3869a20c13f Mon Sep 17 00:00:00 2001 From: Wildan M Date: Tue, 4 Jun 2024 08:26:46 +0700 Subject: [PATCH] Add userclean.sh --- userclean.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 userclean.sh diff --git a/userclean.sh b/userclean.sh new file mode 100644 index 0000000..7ddc523 --- /dev/null +++ b/userclean.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# deletes orphan linux users +rm -rf /var/lib/sss/db/* +getent passwd | sort -t: -k6 | while IFS=: read -r u _ _ _ _ d _ +do + if [[ "$d" =~ ^/home/ ]] && ! [[ -d "$d" ]]; then + printf 'Directory %q missing for user: %q\n' "$d" "$u" + userdel -r $u + fi +done