Question: In Linux(Shell Script), Consider the file newUsers.csv. This is a comma separated list of New users which must be added to your system. A sample
In Linux(Shell Script),
Consider the file newUsers.csv. This is a comma separated list of New users which must be added to your system. A sample entry for the file is given below:
John Smith,1201,Babylon,CST Admin,/home/CSTStudents/JS
The Description of the entries is as follows:
- Field 1 Describes the user name.
- Field 2 Identifies the UID for the user. This field is ignored if the specified UID already exists for some other some user (just do the useradd command without the UID flag).
- Field 3 identifies the group that this user should be assigned to. If this group does not already exist the group should be created.
- Field 4 identifies the comment field (gecos) field that should be associated with the user.
- Field 5 identifies the home directory for that user. If this directory does not exist than it should be created.
Write a program addUsers that is a bash script that will take as a mandatory argument a file name whose contents is assumed to be like newUsers.csv. Your script should be able to handle the following options:
| -d | This option will force all user accounts that are created by this system to be disabled after the given number of days. |
| -p | This will force all users being created to have the same password (passwd). When using this option the password must be changed in 1 day. |
| -s | This option will force the created user(s) to use the same skeleton directory structure which is specified as the dir argument |
| -r | The -r option specified the name of a file to save the usernames and generated passwords to, in the format username:password (one per line). |
The bash script will go through and:
- Test to see if the specified file exists and is readable.
- Add all the users in the specified file to the system according to the dictates listed above.
- The -p option is not given above then assign a password to each user which consists of the string Pass and the UID of the user. For the John user specified above than the password should be Pass1201.
- Hint: Remember why you probably dont want to use the p option to useradd
If a second optional argument is supplied to the script, it should be the name of a file to save the usernames and generated passwords to, in the format username:password (one per line).
The script should be well documented and provide usage notes to the user if they invoke it with too few or too many arguments. The script should exit with an error status and feedback to the user if it encounters problems. It should use the following exit statuses for these specific problems:
- Exit status 3 Improper arguments supplied
- Exit status 4 The supplied file doesnt exist or isnt readable
- Exit status 5 Cannot write to the optional username and password file
- Exit status 6 Specified skeleton directory structure does not exist.
- Exit status 7 The command to add a user fails for any other reason.
Other errors can use exit statuses of your choice.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
