|
| 1 | +Scenario: |
| 2 | +Imagine that you're working as a Linux System Administrator for a fast growing company. The latest company initiative requires you to build and deploy dozens of servers. You're falling behind schedule and are going to miss your deadline for these new server deployments because you are constantly being interrupted by the help desk calling you to create new Linux accounts for all the people in the company who have been recruited to test out the company's newest Linux-based application. |
| 3 | +In order to meet your deadline and keep your sanity, you decide to write a shell script that will create new user accounts. Once you're done with the shell script you can put the help desk in charge of creating new accounts which will finally allow you to work uninterrupted and complete your server deployments on time. |
| 4 | + |
| 5 | +Requirements: |
| 6 | +The script: |
| 7 | + |
| 8 | +- Is named "add-local-user.sh". |
| 9 | + |
| 10 | +1. Enforces that it be executed with superuser (root) privileges. If the script is not executed with superuser privileges it will not attempt to create a user and returns an exit status of 1. |
| 11 | + |
| 12 | +2. Prompts the person who executed the script to enter the username (login), the name for person who will be using the account, and the initial password for the account. |
| 13 | + |
| 14 | +3. Creates a new user on the local system with the input provided by the user. |
| 15 | + |
| 16 | +4. Informs the user if the account was not able to be created for some reason. If the account is not created, the script is to return an exit status of 1. |
| 17 | + |
| 18 | +5. Displays the username, password, and host where the account was created. This way the help desk staff can copy the output of the script in order to easily deliver the information to the new account holder. |
| 19 | + |
| 20 | +After coming up with your list, you realize that you're not sure where to get the hostname information. You decide to wait until you start writing your shell script to check the bash man page to see if there are any builtin commands or variables that could provide this information |
| 21 | + |
| 22 | + |
| 23 | +Psuedo Code: |
| 24 | + |
| 25 | +# Make sure the script is being executed with superuser privileges. |
| 26 | + |
| 27 | +# Get the username (login). |
| 28 | + |
| 29 | +# Get the real name (contents for the description field). |
| 30 | + |
| 31 | +# Get the password. |
| 32 | + |
| 33 | +# Create the user with the password. |
| 34 | + |
| 35 | +# Check to see if the useradd command succeeded. |
| 36 | + |
| 37 | +# Set the password. |
| 38 | + |
| 39 | +# Check to see if the passwd command succeeded. |
| 40 | + |
| 41 | +# Force password change on first login. |
| 42 | + |
| 43 | +# Display the username, password, and the host where the user was created. |
| 44 | + |
0 commit comments