Write a Bash shell script \"userInfo\" that docs the following: Asks the user to
ID: 3764822 • Letter: W
Question
Write a Bash shell script "userInfo" that docs the following: Asks the user to enter the user ID. Read file "passwdSample.txt" (below) file in the present working directory Displays: login Name , user name, uid, gid, pathname for user's home directory, and shell A line format in the passwdSample.txt file looks as follows: Where, Username: It is used when user logs in. It should be between 1 and 32 characters in length. Password: An x character indicates that encrypted password is stored in /etc/shadow file. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups. Group ID (GID): The primary group ID (stored in /etc/group file) User ID Info: The comment field. It allow you to add extra information about the users such as user's full name, phone number etc. This field use by finger command. Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes / PasswdSample.txt Administrator:*:500:513:U-nazeer-PCAdmin:/home/Administrator:/bin/bash Guest:*:501:513:U-nazeer-PCGuest:/home/Guest:bin/bash nazeer:*:1000:513:U-nazeer-PC azeer: /home/nazeer: /bin/sh Sample execution of your program: %userInfo nazeer Login name: nazeer User Information: U-nazeer-PC azeer Uid: 1000 Gid: 513 Home directory: /home/nazeer Shell: /bin/shExplanation / Answer
Bash shell script
#!/bin/bash
#Ask user for user ID
echo -n "enter user ID : "
# read user ID to a variable
read -r uName
# read the text file
# read ech line into seven variables delimitted by ":"
while IFS=: read -r f1 f2 f3 f4 f5 f6 f7
do
# first field in text file is user ID. So compare f1 with uName
if [ "$f1" == "$uName" ]
then
# if matches then print all the user data
echo "Login name: $f1"
echo "User Information: $f5"
echo "Uid: $f3"
echo "Gid: $f4"
echo "Home directory: $f6"
echo "Shell: $f7"
fi
done <passwdSample.txt
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
passwdSample.txt
Administrator:*:500:513:U-nazeer-PCAdmin:/home/Administrator:/bin/bash
Guest:*:501:513:U-nazeer-PCGuest:/home/Guest:/bin/bash
nazeer:*:1000:513:U-nazeer-PC azeer:/home/nazeer:/bin/bash
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.