30 lines
668 B
Bash
Executable File
30 lines
668 B
Bash
Executable File
#!/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
|
|
|
|
|