Lab: While Read

In this Lab you will create your own version of a popular Linux utility, who. Your version, who2 will add two new pieces of information to the output of who, which may be useful here in our environment at CCSF. The two pieces of in formation are:

Here is the sample output of who and the corresponding output of who2:

for the who output:

bwong20  pts/3        2016-11-26 15:10 (76.14.86.50) 
smusarra pts/7        2016-11-26 13:24 (47.152.155.158) 
uwostner pts/14       2016-11-26 14:37 (70.36.157.163) 
uwostner pts/25       2016-11-22 13:43 (70.36.157.160)

who2 outputs the following

S bwong20  pts/3        2016-11-26 15:10 (76.14.86.50) [Benji] 
S smusarra pts/7        2016-11-26 13:24 (47.152.155.158) 
F uwostner pts/14       2016-11-26 14:37 (70.36.157.163) [Ulf Wostner]

The passwd entries for these users are below:

uwostner:x:326:208:Ulf Wostner,Cyberspace,:/users/uwostner:/bin/bash 
bwong20:x:30663:506:Benji,I don't have an office!,,:/students/bwong20:/bin/bash 
smusarra:x:38498:506:smusarra:/students/smusarra:/bin/bash 

Note that

You can decide if someone is a student or faculty by looking at the passwd entry's gid field and comparing it to the gid of the groups STUDENT_GROUP and FACULTY_GROUP which are variables set in the starting version of your shell script. See the labs directory beneath our public work area on hills for who2.

This script is pretty easy if, after translating STUDENT_GROUP and FACULTY_GROUP to their corresponding group ids (which must be done in code, not by entering the group id by hand), you start with a while read loop that reads a line at a time from the output of who (possibly with some additional processing) and process each line.

Turn in who2 when you are finished on Canvas