Link to home
Start Free TrialLog in
Avatar of mrkjudd
mrkjudd

asked on

help with shell scripting

hi can anyone help me with shell scripting
i need to make a script that has an initial menu like below

1.Add Users
2.Delete Users
3.Modify Users
4.Exit

1.Add Users
when add users is selected the script should request a filename containing the user details , this file is going to have three fields the first name, fullname and group
for example it will add the user john , full name john smith , group1 and a passwd should be assigned also which will be listed in a text file with each successful user added., so basically the add user function needs to read a file, add each user from the file to the group and  specify a password all of which will be displayed in a usersadded textfile

2.the delete user function need to request a groupnumber and then search through the etc/password file and delete all users belonging to that group

3.Modify User Groups
the function should ask for a username , and then allow the user to enter the old user group and then enter the new user group

4.Exit
(very straight forward i can do this one)

if anyone can help me with all of this or seperate parts it would be greatly appreciated :) :)
Avatar of cdillon
cdillon

What distribution of linux (including version number) are you using?
For deletion of users belonging to a particular group:

echo -n "Enter the group ID to be deleted: "
read GID
echo $GID | awk 'BEGIN {FS=":"} {
                       GID = $1
                       while (getline < "/etc/passwd" != 0)
                               if ($4 == GID) {
                                       CMD = "userdel -r "$1
                                       system(CMD)
                               }
            }'

This will delete entries from /etc/passwd, /etc/shadow, remove their home directory & also remove their mail spools.
Avatar of mrkjudd

ASKER

im using redhat 8.0
Avatar of mrkjudd

ASKER

that should be fine for deleting users i think :)
ASKER CERTIFIED SOLUTION
Avatar of majorwoo
majorwoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just a couple of ideeas:

1. You cannot use majorwoo's scripts, since greping that way will not ensure that the number involved is the GID. It can be any substring that matches.
You should use qwyjebo's script. That means awk. Awk will also help you fomat nicely the files.

2. Maybe you can have a look at dialog. It is a small utility to display dialog boxes in text mode, in shell scripts, and probably it would make your script look nicer. As I remember, dialog is available for RH (but I'm not sure)
(Yes, RHL8.0 does have dialog and gdialog.)
Avatar of mrkjudd

ASKER

can anyone help with adding users im having some problems
ok, so back here - what problems are you having?
Avatar of mrkjudd

ASKER

thanks for the help