LINUX User Administration Script: Create a script that will assist in retrieving
ID: 3779666 • Letter: L
Question
LINUX
User Administration Script: Create a script that will assist in retrieving user information and meet the following requirements:
Build your script so 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).
EXPECTED FUNCTION AND OUTPUT:
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 when a user is not found):
bob:x:1001:1001:Ops:/home/bob:/bin/bash
bob:x:1001:
ops:x:1004:bob, franks
NOTE: I am using Webnimal virtual Linux machine to run this script.
Explanation / Answer
UserDetail=`getent passwd $1`
Response=$?
if [ $Response -eq 0 ]; then
echo $UserDetail
else
echo "User Does Not Exists"
fi
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.