On Thu, Jun 07, 2001 at 07:26:12PM +0200, Raven wrote:
> I want it to count like this:
> -----------
> SLCT1000
> SLCT1001
> SLCT1002
> etc...
>
> but it count
> -------------
> SLCT1000
> SLCT1002
> SLCT1005
> SLCT1011
> etc..
> #!/usr/bin/perl
#!/usr/bin/perl -w
use strict;
> $newpass = "newhtpasswd";
> $random = "randompasswd";
> $base = 1000;
> $prefix = "SLCT";
> $lenght = 8;
$lenght is misspelled (it should be $length), though you do it consistently,
so it shouldn't cause a problem.
> $passwdfile = "test";
> $kundlista = "lista.txt";
>
> print "How many passwords do you want to create? ";
> chomp ($antal = <STDIN>);
>
> while ($antal > 0) {
> log_pass();
> to_file();
> $antal--;
> }
>
> sub log_pass {
> @pwfile = `cat $passwdfile';
> $size = @pwfile;
> $logname = "raven";
> $base += $size;
>
> while ('grep $logname $passwdfile') {
This is your problem, and I'm surprised you're not seeing an infinite loop.
'grep $logname $passwdfile' is a literal string, which is always true.
Perhaps you meant `grep $logname $passwdfile`, but even then, the return
value of that is never going to change because you're not modifying the file
to remove the matches grep will find. Perhaps what you really meant was
foreach (`grep $logname $passwdfile`) {
> $base++;
> $logname = "${prefix}${base}";
> }
> $passwd = '$random $lenght';
> system ("$newpass $passwdfile $logname $passwd");
> }
>
> sub to_file {
> $filedate = 'date +%Y%m%d';
> open (FILE, ">>$kundlista") || die "can't open file";
Good error checking, though you may want to add $! to your output somewhere,
so if something breaks you have some idea why.
> print FILE "--------------------\n";
> print FILE "Regdate: $filedate";
> print FILE "Login: $logname\n";
> print FILE "Password: $passwd\n";
> close (FILE) || die "can not close file";
> }
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--