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).
- -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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started