Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a shell script named check_accounts which will check some accounts for con

ID: 3545842 • Letter: W

Question

Write a shell script named check_accounts which will check some accounts for consistency.


1st scenario: See if a group ID exists in etc/passwd file but that group ID is non existant in the etc/group file. If you have group ID in both it envokes a OK under Group ID in the output and if otherwise it envokes a No group response.


2nd scenario: See if multiple accounts have the same user ID in the etc/passwd file. If there is only one user ID in the etc/passwd file it will envoke a OK under User ID. If there is multiple user ID in the file it should envoke the number of User ID used.


Your script should produce a report like the following:


Account Summery

Account        Group ID     User ID

-----------        ------------     ----------

root                 OK                  OK

root2               NO group     123




This is what I have so far not sure if it is correct PLEASE HELP:



#!/bin/sh



echo "  Account Summery  "
echo "Account  Group ID  User ID"
echo "-------  --------  -------"




for i in $@
do

user_id=`grep ^$i /etc/passwd | cut -d : -f3`
count= `grep -c $user_id /etc/passwd`

if [$count -gt 1]
then
    echo "$count"
else
    echo "OK"
fi
    

group_id=`grep ^$i /etc/passwd | cut -d : -f4`
group_id2=`grep ^$i /etc/group | cut -d : -f3`

if [ "$group_id" -eq "$group_id2"]
then
    echo "OK"
else
    echo "No Match"
fi

echo "$i   ###SOME OTHER STUFF SHOULD GO HERE TO DISPLAY PROPERLY##  "
done


Explanation / Answer

#!/bin/sh

echo " Account Summery "

echo "Account Group ID User ID"

echo "------- -------- -------"


while read line

do

user=`echo $line | awk -F: '{print$1}'`

group=`echo $line | awk -F: '{print$5}'`

count=`grep -c $user /etc/passwd`

if [[ `grep -i -s $group /etc/group` ]];then

echo "$user OK OK"

else

echo "$user NO GROUP $count"

fi

done< /etc/passwd



####################OUTPUT####################

Account Summery

Account Group ID User ID

------- -------- -------

root OK OK

bin OK OK

daemon OK OK

adm OK OK

lp OK OK

sync NO GROUP 1

shutdown NO GROUP 1

halt NO GROUP 1

mail OK OK

news OK OK

uucp OK OK

operator NO GROUP 1

games OK OK

gopher OK OK

ftp OK OK

nobody OK OK

nscd OK OK

vcsa NO GROUP 1

pcap NO GROUP 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote