Question: Shell Scripts (Linux) Write a script called 'parser' with the following usage: USAGE: parser [-h] parser [-f filename] [-h] username There are two forms for

Shell Scripts (Linux)

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:

1) A filename does not follow the -f switch

2) The filename passed does not exist in the current directory

3) An illegal switch is passed

4) The mandatory username is not given when the -f switch is given, even if a filename is given

5) Too many arguments are given

6) Too few arguments are given (i.e. the user does not give at least 'parser -h' or 'parser ')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!