Hello,
I am trying to write a shell script that maintains the health of the passwd file. The goal is to check for duplicate usernames, UID's etc. I am able to find and sort out the UID and login names via awk (which I would like to use), but I can't figure out how to save the record field into a `sh` variable so I can use it for further testing. The algorithm I think of is:
- Read in passwd file
- determine field seperator
- save the UID field ($3) in shell variable.
- continue and save the next UID field in another shell variable
- compare the two UID's
- if the same print user notification
- else, continue
echo "Check for root uid..."
16 awk -F: '$1 ~/root/ {print "Found Root ID"}' ~/script/passwd
17
18 echo "Check for duplicate user id's..."
19 counter=0
20 for line in ~/script/passwd; do
21 uidcurrent=`awk -F: '$3' ~/script/passwd`
22 if [ $counter -eq 0 ]; then
23 counter=`expr $counter+1`
24 uidprevious=$uidcurrent
25 continue
26 elif [ $uidprevious -eq $uidcurrent ]; then
27 echo "Duplicate UID found"
28 else
29 echo "..."
30 uidprevious=$uidcurrent
31 fi
32 done
33 echo "Duplicate UID check done"
34 echo "Check for duplicate login names..."
35 exit 0
I appreciate your time and effort.
-Daniel