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

Hello there, I need help with answering this question of Linux Shell Scripts. La

ID: 3585109 • Letter: H

Question

Hello there, I need help with answering this question of Linux Shell Scripts.

Lab Writeup:

Write a script called 'parser' with the following usage: USAGE: parser [-h] parser [-f filename] [-h] username There are two forms for the script. The first form simply displays the usage statement, -h is a flag for help. Unacceptable syntax or -h should display the usage statement. The second form must contain a mandatory username with an optional -h or -f argument. The script will display whether or not the username is logged on. One way to do this is to use the following command and do a comparison on the resulting count (assuming you created the username variable in your script): who | grep $username | wc -l When the -h option is specified, show the usage statement as above. When the -f option is specified, it must be followed by a filename. The -f option will display the number of lines in filename, if the file exists. The script should allow for all optional and mandatory command line arguments to be in any order. The script must trap for the following fatal errors, display an appropriate message and exit: A filename does not follow the -f switch The filename passed does not exist in the current directory An illegal switch is passed The mandatory username is not given when the -f switch is given, even if a filename is given Too many arguments are given Too few arguments are given (i.e. the user does not give at least 'parser -h' or 'parser ').

Explanation / Answer

#!/bin/bash

if [ "$1" == "-h" ]; then
echo "Help of parse "
echo " parser -h for help "
echo " parser -f username prints whether or not username present"

elif [[ "$1" == "-f" ]]; then
#statements
    if [-z "$2"];
      then
      echo "No username is given type parse -h for help";
     elif [[! -z "$3" ]]; then
        #statements
        exit;

       else
      who | grep $username | wc -l ;
    fi;
elif [[ -z "$2" ]]; then
#statements
echo "Too many arguements enter parser -h for help"
exit;

elif [ "$1" !="-h" ] && [ "$1" !="-f" ];
#statements
echo "Invalid arguemnts "
echo "Help of parse "
echo " parser -h for help "
echo " parser -f username prints whether or not username present"

done

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