Project 1 audit user
This commit is contained in:
29
week 1/projects/User audit Script/userAudit.sh
Executable file
29
week 1/projects/User audit Script/userAudit.sh
Executable 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user