Hi
I am trying to set new passwords for new users in an ldif list. The passwords are currently set to xyz456. When I run the script and print the array element $genpass[0] I don't get the error. When I run it with the susbstitution I get the uninitialized value error. Please shed some enlightenment for me gracious monks.
#!/usr/bin/perl -w
use strict;
my $p = 1;
my @genpass;
my $genpass;
my $pass = "/home/v0x9849/scripts/new.pass";
open (PASS, ">", $pass) or die "Cannot open $pass: $!";
while ( $p < 53 ){
@genpass = generatePassword(10);
print PASS "@genpass \n";
$p++;
}
close PASS;
open (PASS, $pass) or die "Cannot open $pass: $!";
@genpass = (<PASS>);
my $a;
my $users = "/home/v0x9849/scripts/new.users";
open (USERS, $users) or die "Cannot open $users: $!";
my @nup = (<USERS>);
close USERS;
open (USERS, ">", $users) or die "Cannot open $users: $!";
foreach (@nup){
# print "$genpass[0]\n"; <==this works
s/xyz456/$genpass[0]/; <==this gets uninitialized
#print USERS;
$a = shift(@genpass);
}
close USERS;
#print generatePassword(10) . "\n";
#exit;
sub generatePassword {
my $length = shift;
my $password = "";
my $possible = 'abcdefghijkmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWX
+YZ';
while (length($password) < $length) {$password .= substr($possible, (i
+nt(rand(length($possible)))), 1);}return $password}
Grandfather, here is the data file. This is repeated 52 times with a blank line between each user's info. This line is constant with all entries and in the same place each time: userPassword: xyz456
__DATA__
dn: uid=1234567,ou=people,dc=abc,o=oursite.com
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: 1234567
cn: 1234567
uidNumber: 31472
gidNumber: 7546
gecos: First Last,ABCDEFG297,#######
homeDirectory: /home/1234567
loginShell: /bin/csh
userPassword: xyz456 <==constant line
@ig, @graff There are 728 lines total including blanks between each user's data entry. When I set the iterations to 728 it made the file 0 bytes. However this does seem reasonable as it would have to go through each line. Any ideas on how to prevent it from going to 0 bytes?
@desemondo The only thing copied is the password generation script which is not the issue. When I tried your suggestion with 53 iteration I got the same error. When I tried it with 728 it also made the file 0 bytes.
@jwkrahn That may work but we are not allowed to add modules to our workstations.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.