Please provide the script, logfile, and input file to do the following on Ubuntu
ID: 3869117 • Letter: P
Question
Please provide the script, logfile, and input file to do the following on Ubuntu server:
User account creation script
Write a shell script that will create user accounts and set their home directories. The script will be ran on an Ubuntu server so make sure to research the use of the useradd command in this flavor of Linux. The account creation will be as follows:
Input file format
Your script will read the account information from a text file which has the following format
FirstName,LastName,PhoneNumber,email
Reading the File
Your script will read the file line by line and will create the account as follows
Your script must generate a user name with the following format
FirstLetterOfFirstNameLastName
Example
for user Bill Roberts, the user name created must be brobberts. In case the user name is already taken your script must add a number from 1 to as many numbers needed. Some repeated user names could be of the following format:
brobberts
brobberts1
brobberts2
The user account's password
Your script must also create a random password for each user. In order to do this, you will need to install a tool called pwgen
sudo apt-get install pwgen
To generate the password on the command line type:
pwgen 14 1
This generates a string of 14 characters
Creating the account
Once you have those two components, your script must execute the useradd command. After the account was successfully created, your script must create a public_html directory under the user’s home directory.
Log File
After the user account is created and its home directory is configured correctly, your script must output the username, password and home directory absolute path to a userCreation.log file.
Deliverable (3 Files)
You must provide your shell script, user creation log file, and the input file.
Explanation / Answer
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.