Kyle Burton on Mon, 17 Jan 2000 08:59:54 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] check for existing user


Since there's a possibility of the regex failing with grep 
(uppercase/lowercase, other fields from the passwd file containing 
the same pattern -- what about NIS, shadow password files, etc...), 
is it an option to just use another utility?

id(1) for instance?  I'd be the same methodlogy, checking the return value
(0 - success, other - error).  Internatly, id(1) uses getpwnam(3) (or
something close to it) -- which is 'authoritative' as far as getting 
informaion from the password file.  

so you'd just use id in place of grep:

  id $USERNAME > /dev/null 2>&1


k

------------------------------------------------------------------------------
"Eeny, Meeny, Jelly Beanie, the spirits are about to speak!" 
    -- Bullwinkle Moose
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------

On Sun, 16 Jan 2000, Michelle Weber wrote:

> That was my first thought, but then grep returns the lines which that
> appears, and what if it is in another field besides the first field? (Like
> name or something) - (ok i answered my own question, use a regexp, but im
> trying to make this really simple! and I kinda forget how to do regexps
> anyway...)
> I was thinking of just using the command id, but for either grep or id,
> how do I make a variable equal to true or false depending on what grep or
> another command returns? (in bash)
> 
> -- 
> Michelle Weber
> umweber@mcs.drexel.edu
> 
> 
> On Sun, 16 Jan 2000, Bill Jonas wrote:
> 
> > > What would be the easiest way to check for an existing user with a shell
> > > script? So that if it does exist i can do one thing, and if it doesn't i
> > > can do another?
> > 
> > Grep the /etc/passwd file?  Does grep give a return value?
> > 
> > Bill
> > 
> > --
> > "Because they know that all they sold you was a guaranteed POS!  Look, if
> > you want me to take a dump in a box and mark it 'guaranteed', I will.  I got
> > spare time."
> >  -Chris Farley (on Microsoft?), _Tommy Boy_
> > 
> > 
> > 
> > 
> > 
> > ______________________________________________________________________
> > Philadelphia Linux Users Group       -       http://plug.nothinbut.net
> > Announcements - http://lists.nothinbut.net/mail/listinfo/plug-announce
> > General Discussion   -   http://lists.nothinbut.net/mail/listinfo/plug
> > 
> > 
> 
> 
> ______________________________________________________________________
> Philadelphia Linux Users Group       -       http://plug.nothinbut.net
> Announcements - http://lists.nothinbut.net/mail/listinfo/plug-announce
> General Discussion   -   http://lists.nothinbut.net/mail/listinfo/plug
> 
> 


______________________________________________________________________
Philadelphia Linux Users Group       -       http://plug.nothinbut.net
Announcements - http://lists.nothinbut.net/mail/listinfo/plug-announce
General Discussion   -   http://lists.nothinbut.net/mail/listinfo/plug