Question: Write a script shellsearch with options that displays user information based on the users shell by searching an /etc/passwd-like file. The command will allow these

Write a script shellsearch with options that displays user information based on the users shell by searching an /etc/passwd-like file. The command will allow these options (explained in more detail in the instructions below):

Option

Description

-a

Display users with all shells. Cannot be used with -s.

-f FILE

Search in FILE. FILE must be formatted like /etc/passwd.

-h

Display usage information.

-s SHELL

Display users with SHELL shell. SHELL must be in /etc/shells. Cannot be used with -a.

You should reference the supplied sample output and make your formatting and wording match. For any wording you cannot see in the sample, follow the general style of the sample.

Your script should do the following:

  • Use getopts and allow for the following options to be used:
    • -a: Display users with any shell. Cannot be used with -s. If used with -s, program should display an error and exit with status 1.
      • Sample use: ./shellsearch -a
    • -f FILE: Search in FILE. FILE must be formatted like /etc/passwd. If FILE is not a file or not readable display an error and exit with status 1.
      • Sample use: ./shellsearch -f /etc/passwd
    • -h: Display usage information for all options then exit with status 0.
      • Sample use: ./shellsearch -h
    • -s SHELL: Display users with SHELL Shell specified must be in /etc/shells, otherwise display an error and exit with status 1 (you could accomplish this with a grep). Cannot be used with -a. If used with -a, should display an error and exit with status 1.
      • Sample use: ./shellsearch -s /sbin/nologin
    • If the script is run with no options, display the usage information (same as -h).

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 Finance Questions!