Last active
February 14, 2023 04:48
-
-
Save akiirui/f00a0be95d247fb59d9cf56b41d54510 to your computer and use it in GitHub Desktop.
Manual clean non-exists sysusers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -l CHEKC_CACHE_DIR /tmp/check-sysusers | |
mkdir -p "$CHEKC_CACHE_DIR" | |
# Print non-exists system users | |
cat /etc/passwd | string split -f1 ':' | sort >"$CHEKC_CACHE_DIR/current.users" | |
cat /usr/lib/sysusers.d/* | rg '^u' | string split -n -f2 ' ' | sort >"$CHEKC_CACHE_DIR/preset.users" | |
set -l list_users (sort "$CHEKC_CACHE_DIR/current.users" "$CHEKC_CACHE_DIR/preset.users" | uniq -u) | |
if test -n "$list_users" | |
echo 'Users are not listed in /usr/lib/sysusers.d/:' | |
echo "$list_users" | |
end | |
# Print non-exists system groups | |
cat /etc/group | string split -f1 ':' | sort >"$CHEKC_CACHE_DIR/current.groups" | |
cat /usr/lib/sysusers.d/* | rg '^u|^g' | string split -n -f2 ' ' | sort >"$CHEKC_CACHE_DIR/preset.groups" | |
set -l list_groups (sort "$CHEKC_CACHE_DIR/current.groups" "$CHEKC_CACHE_DIR/preset.groups" | uniq -u) | |
if test -n "$list_groups" | |
echo 'Groups are not listed in /usr/lib/sysusers.d/:' | |
echo "$list_groups" | |
end | |
rm "$CHEKC_CACHE_DIR"/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment