home Mail List
Info
Info
Meetings
Goals
Upcoming
Projects
FAQ
Security
Links

[Date Prev][Date Next] [Chronological] [Thread] [Top]

[NMLUG] grep help



My $0.02 I'm guessing you're going to use it in conjunction with another
script?

-----------------
#!/bin/bash

#
# Usage ./igm <user> <group>
#       Prints 'IN' if is member 'NOTIN' if not.
#

# What to print when in
IN="IN"
# What to print when not in
NOTIN="NOTINI"

if [ -z "$1" ] || [ -z "$2" ]; then
        echo "Usage: $0 <username> <group>"
        echo "   Prints 'IN' if <username> is member of <group>"
        echo "   Prints 'NOTIN' if <username> is not a member of <group>"
        echo ""
        exit;
fi

MEMBER=`egrep "^$2[,:]" /etc/group | egrep "[,:]$1([,:]|$)"`

if [ -z "$MEMBER" ]; then
        echo "$NOTIN"
else
        echo "$IN"
fi
-----------------

On Wed, Mar 16, 2005 at 02:39:28PM -0700, Ed Heron wrote:
>  I'm writing a bash script that needs to check if a particular person is in 
> a specific group.
> 
>  I'm using:
> 
> if grep "^${group}:.*[:,]${user}[,$]" /etc/group >/dev/null ; then echo 
> "${user} is a member of ${group}" ; fi
> 
>  Unfortunately, if $user is last in the list it appears to be false.  If I 
> `grep "^${group}:.*[:,]${user}$" /etc/group` it succeeds.
> 
>  I don't use many regexp, am I missing something? 
> 
> _______________________________________________
> NMLUG mailing list
> NMLUG@nmlug.org
> http://www.nmlug.org/mailman/listinfo/nmlug
> 

-- 

James Hamilton
Southwest Cyberport
http://www.swcp.com
505-232-7992		



Please send sugestions and comments to webmaster@nmlug.org.
Valid XHTML 1.1! Valid CSS! Powered by Debian Powered by Apache