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 :wink:

Greetz
Ali

You can only grep the group file if your machine is not hooked up to nis+ or ldap or something. On linux you could do something like this:

newgrp="somegroup"
if ! getent group $newgroup >/dev/null; then
  newgroup=users
fi 

On HP-UX you can use grget instead of getent group, so it depends what tool you should use. I am sure there are other methods too.

@Scrutinizer: Thank you for this very helpful answer :slight_smile: