Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread m . roth
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 >

Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Stephen Harris
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 --

Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Kwan Lowe
On Mon, Mar 1, 2010 at 11:08 AM, Laurent Wandrebeck 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 t

Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Geoff Galitz
> 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

Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Laurent Wandrebeck
2010/3/1 Niki Kovacs : > 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 >        

Re: [CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Ron Loftin
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

[CentOS] Slightly OT: check creation of a group

2010-03-01 Thread Niki Kovacs
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