[NBLUG/talk] Integrating usernames/passwords

Justin Thiessen thiessen at sonic.net
Fri Apr 1 07:55:12 PST 2005


On Fri, Apr 01, 2005 at 07:01:33AM -0800, Todd Cary wrote:
> If one was responsible for, lets say, 1,000 users and wanted to move the 
> users to another machine, how can one just add those that are not 
> already in the destination machine?
> 
> For example, we have the online machine, "A", and the new machine, "B".  
> pwunconv and grunconv has been run on /etc/passwd and /etc/group, so the 
> task is to add those usernames in the /etc/passwd file on "A" that are 
> not in /etc/passwd on "B" (off course, the shasow files would be 
> recreated after this is completed).
> 
> Will this approach work and is there a script available that checks to 
> see if a username is in the destination and if not, will copy it into 
> the destination?  It has been many years since I wrote some Perl 
> scripts, but I would imagine that with Perl this would be a piece of cake.

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 ;


-----

Justin

thiessen @ sonic.net



More information about the talk mailing list