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

Need some help on this, and please note that this is done wiithin linux. One of

ID: 3851879 • Letter: N

Question

Need some help on this, and please note that this is done wiithin linux.

One of your coworkers needs help with a script that he has been working on but cannot seem to get working. He has copied his bad script, superscript.sh, into your home directory under the scripts directory (~/scripts/superscript.sh). After correcting the script, build a simple script of your own to assist in retrieving user info from SLASH/etc/passwd and SLASH/etc/group to make user administration simpler. A. Correct the Script: Correct your coworker's script, make the script executable (owner and group, not world), execute the corrected script, take a screenshot of the entire script code, take a screenshot of the executed script output, and describe each correction you made to the script to get it working and why you made those changes. B. User Administration Script: Create a script that will assist in retrieving user information and meet the following requirements. Script will be built in your/scripts directory and should be named userlookup.sh. On the second line from the top of the script, below the # !, add a commented line with your name, course, and date followed by a blank newline. Build your script so that it takes the supplied first name of a user and returns the indicated output. The script should retrieve information for the user the script is run against and an error message if no user is found. Users to test will be Bob, Henry, and Notaperson. Bob and Henry should return the correct information and Notaperson should return an error message of no such person found (as there is no Notaperson user). 1. To run script input format: sh userlookup.sh bob sh userlookup.sh henry sh userlookup.sh notaperson 2. Expected output format (will differ based on the user and will display an error for when a user is not found) bob: x: 1001: 1001: Ops: /home/bob: /bin/bash bob: x: 1001: ops: x: 1004: bob, franks

Explanation / Answer

Code:
#!/bin/bash

# program to look user in /etc/passwd and /etc/group and report if found otherwise error

# validating if there is atleast one argument passed
if [ $# -ne 1 ]
then
   echo "One argument must be passed. Usage: $0 <firstname>"
   exit
fi

fname=$1
found=0

# checking if first name is available in /etc/passwd and /etc/group files
grep $fname /etc/passwd /etc/group|cut -d':' -f2-
# checking the exit status of grep command and setting the flag variable found to 1
if [ $? -eq 0 ]
then
   found=1
fi

# verifying if the first name is available in passwd or group files
if [ "$found" -eq 0 ]
then
   echo "No such person found in /etc/passwd and /etc/group file"
fi


Execution and output:
Unix Terminal> sh userlookup.sh daemon
daemon:*:1:1:System Services:/var/root:/usr/bin/false
daemon:*:1:root
Unix Terminal> sh userlookup.sh staff
staff:*:20:root
Unix Terminal> sh userlookup.sh wheel
wheel:*:0:root
Unix Terminal>

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