This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: suggestion for cygutils - usermod (was Re: howto change home path in /etc/passwd)

Bernard Kash wrote:

"Igor Pechtchanski" <> wrote in message

On Mon, 12 May 2003 wrote:

Surlignage Max Bowsher <>: wrote:

Yes , because i don't want to create a shell doing this: grep -v $USERNAME /etc/passwd > /etc/passwd

but i don't know with sed how to delete a line starting with $USER

For the record: "sed '/'$USER':/d". However, grep is perfectly adequate. What Max was warning you about was the shell redirection mechanism. You'd be safer using something like

cp -p /etc/passwd /etc/passwd-bak-tmp && grep -v $USERNAME /etc/passwd-bak-tmp > /etc/passwd && rm -f /etc/passwd-bak-tmp

Unfortunately, if you have a user named Homer that uses 'home' as his userid, the grep will eliminate more users than you might expect. A more realistic example might be two users 'ted' and 'ed' when modifying user 'ed'.

OK then grep -v "^$USERNAME:" /etc/passwd-bak-tmp ...

Also, the mkuser -p option expects a base directory,
so if $HOME is "/home/usrname" the resulting record
will set HOME to "/home/username/username"

I've used awk delete a user from passwd...

awk -F: -v usr=$USERNAME '{IGNORECASE=1; if($1 != usr) print $1;}'


Care! That will leave you with an empty /etc/passwd.
The shell truncates /etc/passwd BEFORE grep reads it.

mkpasswd -l -u $USERNAME -p $HOME >> /etc/passwd



Hope this helps,
     |\      _,,,---,,_
ZZZzz /,`.-'`'    -.  ;-;;,_
    |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
   '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Knowledge is an unending adventure at the edge of uncertainty.
 -- Leto II

-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]