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

UNIX command \"who\" displays all users who is currently on the system The follo

ID: 3575853 • Letter: U

Question

UNIX command "who" displays all users who is currently on the system The following is a sample output of "who" command Write a UNIX shell script to check if a given user is currently login the UNIX system If this user is found, display a message to greet him/her Otherwise display a message indicate the person is not found The following shows how the output should looked like from a few of sample run bash-3.00$ ./checkWho.sh Whom are you checking on? (please provide one parameter) bash-3.00$ ./checkWho.sh mthou Hi mthou, you are on the system now bash-3.00$ ./checkWho.sh S026S962 Hi 30265962, you are on the system now bash-3.00$ ./checkWho.sh 30265666 s0265666 is not on bash-3.00$ ./checkWho.sh ---0265666 0265666 is not on bash-3.00$

Explanation / Answer

vi checkWho.sh
function checkuser
{
f=0;
echo "----------------------------------"
for u in `who | cut -f1 -d" " | sort | uniq`
do
who>userlist
if [ $u = $1 ]
then
echo "hi $1 you are on system now"
grep "$1" userlist|cut -d"(" -f2
f=`expr $f + 1`
fi
done
if [ $f -lt 1 ]
then
echo "$u is not on"
fi
}
if [ -z $1 ]
then
echo "Enter username: "
read k
checkuser $k
echo "----------------------------------" exit 1
fi
checkuser $1
exit 1