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).
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](http://img.homeworklib.com/questions/998c1ed0-9dbf-11ea-9240-a5440b8fd417.png?x-oss-process=image/resize,w_560)
after running script you can verify user by
cat /etc/passwd
Write a script using the bash shell to add new users to the system. The script...
write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...
Write a bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.
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 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 (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 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. 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 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 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") for anyone?