TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG-DEVEL:253] how do I....?



Because I couldn't stand to do anything useful today anyway, I made a
version that actually might do what you want:

>>>>>START>>>>>
#!/usr/local/bin/perl -w

# declare variables
my $htpasswd = "/opt/apache/bin/htpasswd";
my @htpwfiles = qw(
        /home/troy/temp/htpasswd/f1
        /home/troy/temp/htpasswd/f2
        /home/troy/temp/htpasswd/f3
);

# check command line
if (! @ARGV)
{
        print "Usage: $0 <source-file>\n";
        exit 1;
}

# remove old htpasswd files
foreach (@htpwfiles)
{
        print "removing $_\n";
        unlink $_;
}

# recreate htpasswd files from source file(s)
while (<>)
{
        my $command = "";

        chomp;
        my($file, $name, $password) = split;

        if (-e $file)
        {
                $command = "$htpasswd -b $file $name $password";
        }
        else
        {
                $command = "$htpasswd -bc $file $name $password";
        }

        system($command);
}
<<<<<<END<<<<<<

I think I would work it this way unless I had a _huge_ amount of
htpasswd files, then I would read those in from a file too, or generate
a distinct list from the source-file. Hmm...

Troy Johnson wrote:
> 
> Jacqueline,
> 
> This might work after you uncomment the "system" command, but check out
> the printed command lines first:
> 
> >>>>>START>>>>>
> #!/usr/bin/perl -w
> 
> if (! @ARGV)
> {
>         print "Usage: $0 <source-file>\n";
>         exit 1;
> }
> 
> while (<>)
> {
>         chomp;
>         my($file, $name, $password) = split;
>         print "htpasswd -bc $file $name $password\n";
>         #system("htpasswd -bc $file $name $password");
> }
> <<<<<<END<<<<<<
> 
> Also, your perl might be in a different location (which perl), so you
> might have to modify the first line to reflect that. Good luck,
> 
> Troy
> 
> Jacqueline Urick wrote:
> >
> > currently spaces
> >
> > I left my "mastering regular expressions" book at home too... would have
> > been a good day to have that..
> >
> > ~j
> >
> > Troy Johnson wrote:
> > >
> > > I would use Perl. What separates the columns in your source file
> > > (spaces, commas, ...)?
> > >
> > > Jacqueline Urick wrote:
> > > >
> > > > I know there has to to be an easy way to do this with a shell script,
> > > > but I don't know how yet. Perhaps one of you can help me. I have a file
> > > > that has 3 columns, one for the filename, username and then password.
> > > >
> > > > I'm trying to setup a bunch of individual htpasswd files.  How do I make
> > > > a script that looks at the file and then applies it to htpasswd -bc to
> > > > make all my htpasswd files?
> > > >
> > > > Thanks in advance!
> > > >
> > > > Jacque
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> > > > For additional commands, e-mail: tclug-devel-help@mn-linux.org
> > >
> > > --
> > >         <a href="http://umn.edu/~john1536">Troy Johnson</a>
> > >
> > > If you're not part of the solution, you're part of the
> > > precipitate.
> > >                                                 -- Stephen Wright
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> > > For additional commands, e-mail: tclug-devel-help@mn-linux.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> > For additional commands, e-mail: tclug-devel-help@mn-linux.org
> 
> --
>         <a href="http://umn.edu/~john1536">Troy Johnson</a>
> 
> I installed a skylight in my apartment...
> The people who live above me are furious!
>                                                 -- Stephen Wright
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-devel-help@mn-linux.org

-- 
	<a href="http://umn.edu/~john1536">Troy Johnson</a>

I went to a general store.  They  wouldn't  let  me  buy  anything
specifically.
						-- Stephen Wright