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

Write a shell script named group report. This script will accept a list of group

ID: 3545304 • Letter: W

Question

Write a shell script named group report. This script will accept a list of group names on the
command line and produce a group report detailing the group id and the number of group members
identified in /etc/passwd for each group. The report should resemble the following:


    Group Report


Group    GID  Count

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

css          301      439

faculty    300      78


You will notice that the report format is not ideal. This is typical of the results obtained using
echo. You may like to use man echo to learn a little more control techniques for echo. It also seems
like the cut command would be a useful tool for extracting the group id from the proper line of
/etc/group for each group.





Explanation / Answer

According the program given below, the desired output will be printed on the screen as well as stored in a file output.txt in the location from where you run the program.


Usage: ./groupreport.sh GROUP1 GROUP2


Copy the following into a file groupreport.sh and give it executable permission


#!/bin/bash


output="output.txt"


echo "Group Report" > $output

echo "Group GID Count" >> $output

echo "===== === =====" >> $output


for i in $@

do

#Get the group id from /etc/group file

groupid=`grep ^$i /etc/group | cut -d':' -f3`


#Count the number of occurances of groupid in /etc/passwd file

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

echo "$i $groupid $count" >> $output

done


cat output.txt

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