-----Original Message-----
From: Raven <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: June 08, 2001 3:23 AM
Subject: counting problem


>Hi
>
>Can anyone help me with a script that I have made?
>It is a script who are going to add users to a passwd file.
>
>It works fine when I add one user at the time but when I add more
than
>one user the usernumber start to count higher for every user.
>
>I want it to count like this:
>-----------
>SLCT1000
>SLCT1001
>SLCT1002
>etc...
>
>but it count
>-------------
>SLCT1000
>SLCT1002
>SLCT1005
>SLCT1011
>etc..
>
>can anyone help me out?
>
>newhtpasswd is a program who creates a htpasswd like user and
>randompasswd is a program who generates a randm password.
>
>Here is the code.
>-------------
>
>#!/usr/bin/perl
>
>$newpass = "newhtpasswd";
>$random = "randompasswd";
>$base = 1000;
>$prefix = "SLCT";
>$lenght = 8;
>$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') {
>                           $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";
>               print FILE "--------------------\n";
>               print FILE "Regdate: $filedate";
>               print FILE "Login: $logname\n";
>               print FILE "Password: $passwd\n";
>               close (FILE) || die "can not close file";
>}
>
you have $base set up as a global, therefore when you're inserting
more than one password it "remembers" the value of $base from the
previous password.  You could put the initialization of base in the
statement above (only place its used?).  Change your subroutine to
this:
>sub log_pass {
>               @pwfile = `cat $passwdfile';
>               $size = @pwfile;
>               $logname = "raven";
>               $newbase = $base + $size;  <----CHANGE HERE
>
>               while ('grep $logname $passwdfile') {
>                           $base++;
>                           $logname = "${prefix}${newbase}";
<----AND HERE
>               }
>               $passwd = '$random $lenght';
>               system ("$newpass $passwdfile $logname $passwd");
>}

Reply via email to