Question 9 What does the following set of options mean when used as part of useradd instruction? -u 999 -o The user will be given the user ID of 999 which will be unique The user will be given the user ID of 999 which is not required to be unique The user will be given the user ID of 999 which has already been assigned to another account The user will be given the user ID of 999 unless it has already been used in which case the user's ID will be the next available number after 999 None of these, while -u 999 is available, -o is not Question 10 Every user account requires which of the following? A directory A login shell A private group A user ID All of the above Question 11 The shell script below generates user accounts for a group of users whose first and last names are stored in a textfile redirected to the script. #!/bin/bash while read first last; do name="$first $last" username="$last${first:0:1}" n=`egrep $username /etc/passwd` n=$((n+1)) username=$username$n useradd -c "$name" $username done The egrep statement is used to create a username that is unique determine that the given username is unique or else do not create the new account determine the number of username already created matching this user's last name and first initial determine whether the username of the form last name, first initial and number needs to be modified or can be kept as is retrieve the user's username from /etc/passwd
Added by Concepci-N R.
Close
Step 1
Step 1: Access the directory of user information. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 69 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a shell script which is going to do the following: A. Keep asking the user to enter the username through the terminal until the "root" username is entered, then the script will be terminated (hint: use while) (3 points) B. The shell script will pass the value of the username to a function (written inside the same script) which is going to do the following: - Add the user to the system (1 point) - Check if the user addition failed and print a message "Useradd failed" Hint (use "$?" -ne "0" as a condition) -ne means not equal Then exit the function with a value of 1 using (return 1) Note (return will exit from the function while exit will quit the shell script) - Change the user password using the passwd command (1 point) - Check if the password change failed and print a message "Setting password failed" Hint (use "$?" -ne "0" as a condition) (1 point) Then exit the function with a value of 2 using (return 2) Finally, check the value returned by the function using $? If the value is 1, print "Something went wrong with useradd" If the value is 2, print "Something went wrong with passwd" Otherwise, print "added to the system." (1 point) Please check the following example of running this script:
Akash M.
A company has set up a new site and transfer staff and visitor accounts to the new site. Your task is to write a Bash script to create user accounts for all staff and visitors. The supplied user file Usernames.txt is a text file containing a username and its type delimited by comma per line. There are two types of users: staff and visitor. Staff users are added to the staff group and visitor users to the visitors group. 1. Write a Bash script, called createUsers.sh, to do the followings. a) Create two groups called visitors and staff; b) Create an account for each user and add the user to its group in one command. All user accounts are created with an initial password the same as their username; a home directory with the same name as their username in the /home directory; all accounts use Bash shell program. c) Write messages to syslog for all of the above events (new group, new user creation). Note that while the current need is to handle limited number of usernames from the given user file, your script should be able to handle an arbitrary number of usernames. 2. Write a Bash script, called reportVisitors.sh, to report the members of visitors group to the file /tmp/visitors.txt. The output should contain the user names only with each user in a separate line. 3. Create a crontab entry to call the reportVisitors.sh script at 8:00AM and 9:00PM on every weekdays.
Lab 9 Instructions: Open the terminal and using vi/vim create a new script and name it lab9 Insert at the top of your file a comment with your name, class and section number (e.g. #John Doe, EMT 2390L - ABC123). This lab will help a user determine the permissions in a user-friendly way. In your script named lab9 do the following: Show the user the following questions to get the right permissions for the owner, the group, and the world: - Do you want to grant read permissions? - Do you want to grant write permissions? - Do you want to grant execute permissions? Show the appropriate permission in Octal notation according to the following table: Octal Binary File Mode 0 000 --- 1 001 --x 2 010 -w- 3 011 -wx 4 100 r-- 5 101 r-x 6 110 rw- 7 111 rwx Your script should then display to the user the appropriate octal number permission based on the user selection. - e.g. if the user chose read, write and execute for the owner; read and execute for the group; read and execute for the world; your script will show: 755 - e.g. if the user chose read, write and execute for the owner; read and write for the group; read only for the world; your script will show: 764 Save the script and make it executable (HINT: use the chmod command with mode 755). Execute the script (HINT: use dot slash ./ combination, followed by your script name) and fix any errors.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD