[olug] Scripting

Brian Roberson brian at bstc.net
Sat Nov 18 09:22:18 UTC 2000


I hate to say it, but if you have the ability, it is easier and a whole lot
faster to whip up a C prog to do it, but if you have to do it in
perl...........
open a file handle and write the info directly and then convert it if you
have to, to a shadowed password, with the fast C prog ( pwcoonv )
e.g........

#######################################
# EXAMPLE ONLY!!!!! DO _NOT_ TAKE LITTERALLY... JUST A SEMI-CORRECT
GUIDE!!!!!
#
#!/path/to/perl
...
........
............ (BLAH... WHATEVER YOU NEED TO DO )
# set up the new user array with users!
@SOME_USER_ARRAY="foo, blah, junk, fill, it, up";
# get the julian date to add some kind of randomness? make up your own
reasoning!!
$date_part=(localtime(time()))[7];
$shell="/some/shell";
$uid="100000";
$gid="100000";
$gecos="whatever";
# since ther is a alot of users, make it stuctured! (
/home/user.initial/username directory structure )
$home="/home/(substr($user, 0, 1))/$user";
# make the semi-random password
$password="(substr($user, 0, 4))$date_part";
$salt = substr((rand) 0, 2);
# use the standard crypt(3) password ( unix_pw )
# ope n a new paswordfile, and make it!
$passwd=(crypt($password, $salt);


sub DOIT {
open OUT ('+</tmp/newpasswd');
    foreach ( $user, @SOME_USER_ARRAY) {
            print OUT "$user:$pass:$uid:$gid:$gecos:$home:$shell";
# increment the uid/gid
            $uid++;
            $gid++;
        }
 close (OUT);
system("cp -f /etc/passwd /backup/dir/passwd.$date");
system("mv -f /tmp/newpasswd /etc/passwd");
# use the C prog to convert it to a shadow passwd!
system("/usr/sbin/pwconv");
}


#MAKE SURE ALL THE REGULAR USERS ARE IN THERE!!! ( head -$number /etc/passwd
>> /tmp/newpaswd before the script maybe?.... whatever )
 open IN ("/tmp/newpasswd");
            if (/root/ $IN) {
    &DOIT;
}
 close (IN);
###################################################



----- Original Message -----
From: "Andrew Embury" <drazak at materiamagica.com>
To: <olug at bstc.net>
Sent: Friday, November 17, 2000 2:57 PM
Subject: [olug] Scripting


> I'm scripting a system where about 3k users will get added/deleted to a
> RedHat 6.2 system several times a week.
>
> Right now I have a perl script that just uses system() to shell out to the
> useradd command, and then passwd to set the password.  This works fine,
> but is painfully slow.  I think I might need to generate the passwd and
> shadow file manually using crypt() or something.  Can someone provide an
> overview of how this works on RedHat and any problems I might run into?
>
> For example,
>
> How do I tell if /etc/shadow is using MD5 passwords? What problems are PAM
> going to cause me? Can I remove shadow passwords somehow from the system
> and just use standard unix passwords?  (I dont need them in this system,
> all accounts are ftp only).
>
> Thanks for the help.
>
> _Drew
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: olug-unsubscribe at bstc.net
> For additional commands, e-mail: olug-help at bstc.net
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: olug-unsubscribe at bstc.net
For additional commands, e-mail: olug-help at bstc.net



More information about the OLUG mailing list