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
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...
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?
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 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...