FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 03-01-2010, 03:03 PM
Niki Kovacs
 
Default Slightly OT: check creation of a group

Hi,

I'm currently writing an install script for an application, and my
already limited Bash skills are a bit rusty.

I want to check if a group exists, and if it doesn't, then create it.

Only thing I found is:

if [ grep medintux /etc/group ]; then
continue
else
groupadd medintux
fi

Apparently I can't seem to "negate" the test, e. g. something like

if !(grep medintux /etc/group)

Any suggestions for the correct syntax here ?

Thanks,

Niki
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:07 PM
Ron Loftin
 
Default Slightly OT: check creation of a group

On Mon, 2010-03-01 at 17:03 +0100, Niki Kovacs wrote:
> Hi,
>
> I'm currently writing an install script for an application, and my
> already limited Bash skills are a bit rusty.
>
> I want to check if a group exists, and if it doesn't, then create it.
>
> Only thing I found is:
>
> if [ grep medintux /etc/group ]; then
> continue
> else
> groupadd medintux
> fi
>
> Apparently I can't seem to "negate" the test, e. g. something like
>
> if !(grep medintux /etc/group)
>
> Any suggestions for the correct syntax here ?
>

Try this:

grep -q medintux /etc/group || groupadd medintux

> Thanks,
>
> Niki
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
--
Ron Loftin reloftin@twcny.rr.com

"God, root, what is difference ?" Piter from UserFriendly

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:08 PM
Laurent Wandrebeck
 
Default Slightly OT: check creation of a group

2010/3/1 Niki Kovacs <contact@kikinovak.net>:
> Hi,
>
> I'm currently writing an install script for an application, and my
> already limited Bash skills are a bit rusty.
>
> I want to check if a group exists, and if it doesn't, then create it.
>
> Only thing I found is:
>
> if [ grep medintux /etc/group ]; then
> * * * *continue
> else
> * * * *groupadd medintux
> fi
>
> Apparently I can't seem to "negate" the test, e. g. something like
>
> if !(grep medintux /etc/group)
>
> Any suggestions for the correct syntax here ?
>
> Thanks,
>
> Niki
Why don't you use groupadd -f ? It will not override the group if it
already exists, and shortens the code

Laurent
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:09 PM
 
Default Slightly OT: check creation of a group

grep medintux /etc/group || groupadd medintux

or in a if operation:

if [[ ! grep medintux /etc/group ]]
then
groupadd medintux
fi

Regards,
Frank.

Niki Kovacs <contact@kikinovak.net> schrieb am 01.03.2010 17:03:46:

> Hi,
>
> I'm currently writing an install script for an application, and my
> already limited Bash skills are a bit rusty.
>
> I want to check if a group exists, and if it doesn't, then create it.
>
> Only thing I found is:
>
> if [ grep medintux /etc/group ]; then
> continue
> else
> groupadd medintux
> fi
>
> Apparently I can't seem to "negate" the test, e. g. something like
>
> if !(grep medintux /etc/group)
>
> Any suggestions for the correct syntax here ?
>
> Thanks,
>
> Niki
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:12 PM
"Geoff Galitz"
 
Default Slightly OT: check creation of a group

> Apparently I can't seem to "negate" the test, e. g. something like
>
> if !(grep medintux /etc/group)
>
> Any suggestions for the correct syntax here ?
>


I'd do it like this:

grep medintux /etc/group
if [ $? != 0 ]; then
echo "Group not found"
fi



---------------------------------
Geoff Galitz
Blankenheim NRW, Germany
http://www.galitz.org/
http://german-way.com/blog/



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:14 PM
Kwan Lowe
 
Default Slightly OT: check creation of a group

On Mon, Mar 1, 2010 at 11:08 AM, Laurent Wandrebeck
<l.wandrebeck@gmail.com> wrote:

>> Niki
> Why don't you use groupadd -f ? It will not override the group if it
> already exists, and shortens the code
>

That gets my vote

I have seen code that creates a temp file then does a chgrp on the
file. If it fails then the group is created. If not, the existing
group was used. This was done to get around some differences between
SunOS and Linux and unknown state of LDAP/local auth.
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:19 PM
Stephen Harris
 
Default Slightly OT: check creation of a group

On Mon, Mar 01, 2010 at 05:12:15PM +0100, Geoff Galitz wrote:

> I'd do it like this:
>
> grep medintux /etc/group
> if [ $? != 0 ]; then
> echo "Group not found"
> fi

Or allow for naming services (NIS, LDAP, whatever)

if [ -z "$(getent group medintux)" ]
then
groupadd ....
fi

--

rgds
Stephen
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-01-2010, 03:22 PM
 
Default Slightly OT: check creation of a group

Niki wrote:
>
> I'm currently writing an install script for an application, and my
> already limited Bash skills are a bit rusty.
>
> I want to check if a group exists, and if it doesn't, then create it.
>
> Only thing I found is:
>
> if [ grep medintux /etc/group ]; then
> continue
> else
> groupadd medintux
> fi
>
Why not
if [ `grep -c medintux /etc/group` == 0 ]; then
groupadd medintux
fi

?

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 10:04 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org