[NBLUG/talk] Integrating usernames/passwords

Steve Johnson gnuguy at gmail.com
Fri Apr 1 08:53:29 PST 2005


On Apr 1, 2005 7:55 AM, Justin Thiessen <thiessen at sonic.net> wrote:
> On Fri, Apr 01, 2005 at 07:01:33AM -0800, Todd Cary wrote:
> Copy the password file on machine B to "passwd.old", and the password file on
> machine A to "passwd.new", then try the following (note the carriage return
> between the quotes in my reassignation of IFS):
> 
> #!/bin/bash
> 
> OLDIFS=$IFS ;
> IFS="
> "
> for i in `cat passwd.new` ;
>   do
>   if [ $( grep -c `echo $i | sed s/:.*$// -` passwd.old) -eq 0 ] ;
>     then echo $i >> passwd.old ;
>   fi ;
> done ;
> IFS=$OLDIFS ;
> 
> -----

This will work sorta, just be aware, you may have conflicting UID# in
the new file, it would be best to write something in PERL, and have it
verify uid's also.

I had to do this once, and I used perl to build a hash of the new
password file, useing the login name as the key and the uid as the
value, then load in the old password file, if the hash entry allready
was there, then it would drop the name, if it wasn't there, it would
add it to the hash.  The new hash entries value would be a new uid,
starting at whatever was the last one in the new passwd file.

Once I was done with parsing the files, I would then dump the hash to
a file in the proper format for /etc/passwd.. Now if I was also moving
over home directories or any other user directories, I would make sure
to chown those directories, this would insure that the new uid would
stick on them.

I wish I had access to the code I originally used, I would share it,
but the idea should at least get you pointed in the right direction.

-Steve



-- 
      "Knowing others is wisdom, knowing your self is Enlightenment."
                                                   -- Lao-Tzu
|C8H10N4O2|



More information about the talk mailing list