Validate if user and group exist


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Validate if user and group exist
# 1  
Old 03-20-2006
Validate if user and group exist

I'm kinda new to unix programming so bear with me...

I'm running a script prompting a user for an existing user and group and want to be able to validate if they valid.

Is there any code available?

Any help or push in the right direction would help.

Thank you,
# 2  
Old 03-20-2006
here are some pointers ...

1. get input from user and assign that to a variable

2. grep out the variable from /etc/passwd (or whatever file your OS uses) and assign the GID to another variable

3. grep out the GID from /etc/group (or whatever file your OS uses)

... if you can grep out the username and the GID from the appropriate files, then your inout is validated ...

### check man pages for grep, awk, cut and ksh ... good luck!
# 3  
Old 03-21-2006
If you don't want to parse the system user files yourself
you could as well use a system command like id.
e.g.
Code:
echo "enter user:"
read user
if [[ -n $user ]] && id $user >/dev/null 2>&1; then
    # user is known
    # do whatever you like
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Group Doesn't Exist

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I'm able to create a group but when I'm trying to delete the group it keeps stating Group Doesn't Exist. I know... (2 Replies)
Discussion started by: GoBoyGo
2 Replies

2. Shell Programming and Scripting

Find if a User exist if not create user

What I'm trying to do is write a script in Perl to find a user and if that user exist it would print "User Exist, Pls Try Again". If The user doesn't exist I'm able to create a user with a password. Any suggestions? (3 Replies)
Discussion started by: GoBoyGo
3 Replies

3. Red Hat

User is a Part of a Group But Group Details Do Not Show the User

Hi, In the following output you can see the the user "richard" is a member on the team/group "developers": # id richard uid=10247(richard) gid=100361(developers) groups=100361(developers),10053(testers) but in the following details of the said group (developers), the said user... (3 Replies)
Discussion started by: indiansoil
3 Replies

4. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies

5. Red Hat

Removing LVM Volume Group that doesn't exist anymore

Our SAN administrator decided to unpresent then destroy LUN's we were actively using as a volume group (all PV's in said volume group). Now every time I do a pvscan or whatever it complains about I/O errors trying to access those PV's. How do I get it to forget the VG existed completely? vgreduce... (7 Replies)
Discussion started by: thmnetwork
7 Replies

6. UNIX for Dummies Questions & Answers

Removing a user that doesnt exist from a group

Hi there, normally if I want to remove a user tht I have added to a specific group, i would do the following this is what my group2 looks like # grep group2 /etc/group group2:x:7777:user2,user1,user4 user1 has been defined in a few groups # id -nG user1 group1 group2 group3 So... (3 Replies)
Discussion started by: rethink
3 Replies

7. Shell Programming and Scripting

Group Exist Scripting

Hey People, I've got a question! How can i write a function in a script which is looking for if a group exist and if not, that the group "users" is the standard group..I know that i have to use "grep" und "if-else"..I will be very happy for answers ;) Greetz Ali (2 Replies)
Discussion started by: AliC
2 Replies

8. Shell Programming and Scripting

validate user ids

Hi I have to validate the user ids. It should be numeric. I am using following code echo $input | grep '^\{11\} > /dev/null if echo "error" else echo "Success" fi But when i entered user id as 828^&% the output is 8565 8566 -bash: ^: command not found Means when i entered... (4 Replies)
Discussion started by: KiranKumarKarre
4 Replies

9. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

10. UNIX for Dummies Questions & Answers

What hapens if a group member doesn't exist?

As part of a NIS implementation, (I think) I want to create a group (in /etc/group) that has users that do not exist on the target machine. What effect will this have? Will it cause any problems? Thanks, Gary Cooper (1 Reply)
Discussion started by: Gary Cooper
1 Replies
Login or Register to Ask a Question