Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help making this interactive bash script for adding a user to a system, these are the requirements. I'm using Opensuse. Requirements: Write an

I need help making this interactive bash script for adding a user to a system, these are the requirements. I'm using Opensuse.

Requirements:

Write an interactive sript called adduser. Your script should gather all the pertinent information such as user name, group, shell, etc., error check input, then call useradd with the appropiate options and arguments. You will also need to call chfn and passwd for the new user account. You should offer the option of choosing a primary group different from the default, choosing additional groups the new user should be a member of, selecting a home directory different from the default, choosing a shell different from the default, and anything else you think is appropiate for your system. Your script must call the useradd command. Your script's error checking should be comprehensive enough so that when you call useradd it will not generate any error messages.

This is what i have so far, but it is not working, and it also needs to error check the input from the user. I realized I also need to call chfn, but i don't know how to it.

Here is my script. I don't see an option to upload a bash script file in here, but you can copy the script below and paste it.

#!/bin/bash

if [ $(id -u) -eq 0 ]; then read -p "Enter username : " username read -p "Enter password : " password read -p "Enter group id or [default to next available]: " gid read -p "Enter additional groups or [default to next available]: " group read -p "Enter home directory or [default to next available]: " hdir read -p "Enter desired shell or [default to next available]: " difshell

egrep "^$username" /etc/passwd >/devull if [ $? -eq 0 ]; then echo "$username exists!" exit 1 else pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) useradd -p$pass -g$gid -g$group -d$hdir -s$difshell $username [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add user!" fi else echo "Only root may add a user to the system" exit 2

image text in transcribed

noel@linux-miyw: File Edit View Search Terminal Help #!/bin/bash if [ $(id -u) -eq ]; then read -p "Enter usernameusername read -p "Enter password password read -p "Enter group id or [default to next available]: " gid read -p "Enter additional groups or [default to next available] "group read -p "Enter home directory or [default to next available]:" hdir read -p "Enter desired shell or [default to next available]: "difshell egrep "Ausername" /etc/passwd >/devull if $?-eq 0]; then echo "username exists!" exit 1 else pass-$(perl -e 'print crypt ($ARGV[0], "password")' $password) useradd -p$pass -g$gid -G$group -d$hdir -s$difshell username [ $? -eq ] && echo "User has been added to system." Il echo "Failed to add user!" fi else echo "Only root may add a user to the system" exit 2 - INSERT-- 1,12 noel@linux-miyw: File Edit View Search Terminal Help #!/bin/bash if [ $(id -u) -eq ]; then read -p "Enter usernameusername read -p "Enter password password read -p "Enter group id or [default to next available]: " gid read -p "Enter additional groups or [default to next available] "group read -p "Enter home directory or [default to next available]:" hdir read -p "Enter desired shell or [default to next available]: "difshell egrep "Ausername" /etc/passwd >/devull if $?-eq 0]; then echo "username exists!" exit 1 else pass-$(perl -e 'print crypt ($ARGV[0], "password")' $password) useradd -p$pass -g$gid -G$group -d$hdir -s$difshell username [ $? -eq ] && echo "User has been added to system." Il echo "Failed to add user!" fi else echo "Only root may add a user to the system" exit 2 - INSERT-- 1,12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago