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

Create a script called script8.1 that will do the following: Accept a username a

ID: 3567329 • Letter: C

Question

  • Create a script called script8.1 that will do the following:
    • Accept a username as an argument; if one is not provided, ask for it; (Assume that the argument or user input provided is an actual username.)
    • Using the argument (if it's provided) or user input (if it's not), check to see if that user is logged on;
    • Display to the screen an appropriate message: either " is logged on" or " is not logged on"
    • Do not display anything to the screen except the request for a user name, if
      necessary, and the statement that the user is (or is not) logged on.

Explanation / Answer

#! /bin/bash

if [ $# -ne 1 ]
then
echo "Usage: test username"
exit 1
else
LOGIN_CHK=`who | cut -f1 -d" " | grep -i $1 |wc -l`
if [ "$LOGIN_CHK" -gt "0" ]
then
echo "$1 is logged on"
else
echo "$1 is NOT logged on"
fi
fi

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