Redirecting input

Redirecting input

Post by Shawn Dag » Sat, 15 Jan 2000 04:00:00



I am trying to add 1200 users and initial passwords using htpasswd.  I have
the shell script to set up the users but the htpasswd command prompts for
password and a confirmation.  ie

command:
htpasswd "directory" "username"
result:
enter password:

I want to feed the password prompt automatically.  I thought that the
following would work

htpasswd  "directory" "username" <"input file"

Where input file contained 2 lines with the password.  It does not work.

Any help will be appreciated.

Thanks,

Shawn

 
 
 

Redirecting input

Post by Kurt J. Lanz » Sat, 15 Jan 2000 04:00:00



> I am trying to add 1200 users and initial passwords using htpasswd.  I have
> the shell script to set up the users but the htpasswd command prompts for
> password and a confirmation.  ie

> command:
> htpasswd "directory" "username"
> result:
> enter password:

> I want to feed the password prompt automatically.  I thought that the
> following would work

> htpasswd  "directory" "username" <"input file"

> Where input file contained 2 lines with the password.  It does not work.

> Any help will be appreciated.

> Thanks,

> Shawn

If you are referring to the htpasswd that is distributed
with Apache (and I must assume that, even though you
could take any old pile o' code and call it whatever you
want), it reads its password from /dev/tty, not stdin.
This is to prevent scripts like yours. You can hack the
code (I think it's in util.c), but it's been so long
since I had to do it that I'm reluctant to spend the
time in archeology.  If you aren't one, find a
reasonably competent unix/C guy and he'll get it done in
an hour or so.

 
 
 

Redirecting input

Post by Barry Margoli » Sat, 15 Jan 2000 04:00:00




Quote:>If you are referring to the htpasswd that is distributed
>with Apache (and I must assume that, even though you
>could take any old pile o' code and call it whatever you
>want), it reads its password from /dev/tty, not stdin.
>This is to prevent scripts like yours. You can hack the
>code (I think it's in util.c), but it's been so long
>since I had to do it that I'm reluctant to spend the
>time in archeology.  If you aren't one, find a
>reasonably competent unix/C guy and he'll get it done in
>an hour or so.

Or you could just write a trivial Expect script to do it.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Redirecting input

Post by Ken Pizzi » Sat, 15 Jan 2000 04:00:00



>I am trying to add 1200 users and initial passwords using htpasswd.
>I want to feed the password prompt automatically.  I thought that the
>following would work

>htpasswd  "directory" "username" <"input file"

I use the script below for such purposes; make your input file
consist of lines each with the user name, some whitespace, and
the plaintext password.  Then just pass that file to this
script, and redirect the output as desired.

#! /usr/bin/perl -w
use strict;

sub salt { $saltchars[rand(64)] .  $saltchars[rand(64)] }
while (<>) {
    chomp;
    my ($name, $pass) = split;
    print $name, ":", crypt($pass, &salt), "\n";

Quote:}

                --Ken Pizzini
 
 
 

1. Redirecting input to a file - echo the input to screen/file?

Is it possible to have redirected input to a file also echoed to the
screen, or to a file?  For example, if I do something like the following:

$ ./program < input.txt > output.txt 2>&1

The output file shows everything coming out of the program (stdout and
stderr), but doesn't display the input.txt.

I tried adding 0>&1, but no-go (input hosed).

I can also cut and paste the input.txt file right in the shell, but it
doesn't show up for some reason in the shell (Redhat8.0).  Not sure what's
going on, any help appreciated.

2. Yet another KA9Q question

3. How to read redirected input?

4. sis630 - help needed debugging in the kernel

5. Redirecting input and output to serial port

6. tabs and underline in troff!!

7. Redirect input to telnet

8. Problems with Apache on Solaris X86

9. redirecting input to output

10. How to redirect input to ftp "mget" command?

11. Adduser can't deal with redirected input?

12. Problem redirecting input using dup2

13. Redirecting input within sh shell