Question

Write a script using the bash shell to add new users to the system. The script...

Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma).

The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause.

The input file should contain the user information with one user per line.

As the system administrator, you should determine the information necessary for each user to properly add their account. Be sure to include in the program documentation the format for each line (identify each field contents).

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

save below script as adduser.sh

#!/bin/bash
# checking if file was passed or not
if [ "$#" -ne 1 ]; then # comparing not equal to 1
    echo "usage: bash adduser.sh <filename>" # printing usage clause
    exit 1 # if not file exiting
fi
# getting file name
file="$1"
# reading line by comma separated value
while IFS=, read -r user pass
do
    echo "Adding user : $col1"
    # using useradd command for adding user
    useradd -m ${user} -p ${pass}
    echo ""
done <"$file" # reading file


users.csv -> make sure have new line after last record

Alisha,PASSW0R1D
Rohit, PASSW0R1D

U can run script as

sudo bash useradd.sh users.csv

# OUT

$sudo bash adduse r . sh users.csv [sudo] password for roushan: Adding user : Alisha Adding user Rohit $sudo bash adduser. sh

after running script you can verify user by

cat /etc/passwd

Add a comment
Know the answer?
Add Answer to:
Write a script using the bash shell to add new users to the system. The script...
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
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