Question

sing the attached file as a "database" of users, develop an application that reads the users.txt...

sing the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Each user must also have a password, though in the interest of brevity, they may all be assigned the same one. Provide me the source code and a copy of your system's /etc/passwd file. Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is doing, and 2) you write it yourself. Remember to give attribution to any code you use that you didn't write. 1. Pittman,Mckenzie,Sales 2. Donovan,Moriah,Accounting 3. Barnes,Gabriel,Sales 4. Monroe,Maximillian,Management 5. Maynard,Sylvia,Management 6. Mayer,Elise,Accounting 7. Reeves,Stephen,Production 8. Oneill,Sean,Sales 9. Jackson,Hanna,Management 10. Lee,Alani,Production 11. Golden,Ibrahim,Production 12. Tyrese,Todd,Production Annotations.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the following shell script to read the file and create the user with default password as "admin123".

Program:

#!/bin/bash

if [ $# -ne 1 ]
then
echo "Usage: $0 <accounts.txt>"
exit
fi

fileName=$1

#change the default password as needed
defaultPasswd="admin123"


#following awk script cuts the first name and first character from last name to form the username of the account
#example "1. Pittman,Mckenzie,Sales" user name is "pittmanm"

awk -F"," '
{
print $1" "$2
} ' $fileName | awk ' { print tolower($2substr($3,1,1)) }' | while read userName
do
#useradd command is used to add the user name with default password and with home directory
useradd -r $userName -m -p $defaultPasswd
if [ $? -eq 0 ]
then
echo "User: '$userName' is added with default password: $defaultPasswd"
else
echo "User: '$userName' is not added due to error: $?"
fi
done

Output:

User: 'pittmanm' is added with default password: admin123
User: 'donovanm' is added with default password: admin123
User: 'barnesg' is added with default password: admin123
User: 'monroem' is added with default password: admin123
User: 'maynards' is added with default password: admin123
User: 'mayere' is added with default password: admin123
User: 'reevess' is added with default password: admin123
User: 'oneills' is added with default password: admin123
User: 'jacksonh' is added with default password: admin123
User: 'leea' is added with default password: admin123
User: 'goldeni' is added with default password: admin123
User: 'tyreset' is added with default password: admin123

sample file "/etc/passwd" :

pittmanm:x:991:991::/home/pittmanm:
donovanm:x:993:991::/home/donovanm:
barnesg:x:994:991::/home/barnesg:
maynards:x:994:991::/home/maynards:
tyreset:x:993:991::/home/tyreset:

Screen Shot:

#!/bin/bash if [ $# -ne l ] then echo Usage: $0 <DB File> exit fi fileName=$ı defaultPasswd=admin123 #following awk scrip

Add a comment
Know the answer?
Add Answer to:
sing the attached file as a "database" of users, develop an application that reads the users.txt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • UNIX/LINUX "Using the attached file as a "database" of users, develop an application that reads the...

    UNIX/LINUX "Using the attached file as a "database" of users, develop an application that reads the users.txt file, and adds each one as a new user. Each user must also have a password, though in the interest of brevity, they may all be assigned the same one. Provide me the source code and a copy of your system's /etc/passwd file. Note: it is perfectly acceptable to "leverage" code from another source provided: 1) you understand what the example code is...

  • C++ Create an application that searches a file of male and female first names. A link...

    C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT