Project 1 audit user

This commit is contained in:
2026-01-26 08:39:36 +01:00
parent 3e23329086
commit 20dbbbdd77
5 changed files with 104 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# userAudit
#Read the passwd file for all the username
file=$(awk -F ":" '{print $1}' /etc/passwd)
for username in $file; do
firstChar="${username:0:1}"
badChar=false
#check if the username contain only letters
for ((i=0; i<${#username}; i++)); do
char="${username:i:1}"
if ! [[ "$char" =~ [A-Za-z] ]]; then
badChar=true
break
fi
done
#if the username is not valid
# longer than 20 characters, start with not a letter and contain other char than letter
# print it
if ((${#username} >= 20)) || ! [[ "$firstChar" =~ [A-Za-z] ]] || $badChar ; then
echo $username
fi
done