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
  • Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a...

    Exercise 1: Write a shell script that loops through the /etc/passwd file one line at a time. Prepend each line with a line number followed by a colon and then a space. Example output: 1: root:x:0:0:root:/root:/bin/bash 2: daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin 3: bin:x:2:2:bin:/bin:/usr/sbin/nologin 4: sys:x:3:3:sys:/dev:/usr/sbin/nologin Exercise 2: Write a shell script that asks the user for the number of lines they would like to display from the /etc/passwd file and display those lines. Example output: How many lines of /etc/passwd would you like...

  • Problem 1 Write a BASH script to create a user account from the Linux system on...

    Problem 1 Write a BASH script to create a user account from the Linux system on which your script is run. The script should process two positional parameters. First positional parameter is supposed to be a string with a user name (e.g., user_name) Second positional parameter is supposed to be a string with a user password (e.g., user_password) In your script: Check if two positional parameters were passed to your script when it was invoked If NOT, print an appropriate...

  • Problem 4: Write a Bash script that removes all zero length ordinary files in the directory...

    Problem 4: Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with the find command, the find command is not allowed to appear in your...

  • Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the defaul

    Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script such as:If the arguments are more than 1, print out “Too many arguments passed”.If the argument passed is a regular file, print out “XXX is regular file”.1c. If the directory doesn’t exist, print out “Directory...

  • Write a Bash shell script testaverager.sh that will determine if a person has passed a class....

    Write a Bash shell script testaverager.sh that will determine if a person has passed a class. It should take in as a command-line parameter a name (first and last name) as well as a series of numbers. This list could be of any length. Your script should start by calculating the average of the scores. If the result is below 70, it should output “Sorry [name] but you will have to retake the class!”. If the result is 70 or...

  • Programs/scripts 13. Write a bash shell script that displays the date by using the shell command...

    Programs/scripts 13. Write a bash shell script that displays the date by using the shell command date. 14. Write a command line program that takes a number and a command as arguments. Call that command that number of times. For example, if your program name is "test" test 3 dir <shows directory> dir <shows directory> dir <shows directory>

  • How to write a bash shell script that prints a hollow box after user enters number...

    How to write a bash shell script that prints a hollow box after user enters number of lines, ie "bash hbox 4" , prints: **** *   * *   * **** My code doesnt work. i need it to take in the argument from the command line: ./hbox 4 "*" echo "Enter number of rows" read sz clear for (( x = 1; x <= $sz; x++ )); do     for (( y = 1; y <= $sz; y++ )); do...

  • What Linux command should you type to give/add 01-hello bash shell script permission to run ("execute")...

    What Linux command should you type to give/add 01-hello bash shell script permission to run ("execute") for anyone?

  • Write a bash script to protect a directory. Your script should notify a user of the...

    Write a bash script to protect a directory. Your script should notify a user of the following: -New file was created -Permission changes -Ownership changes -File size changes -Modification date changes Your script should have two operation modes, protect and check. Use command line flags, -p <directory> and -c <directory> to decide which mode to operate in. In protect mode, your script should create a file called .protect inside the directory you want to watch. You will use this file...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

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