[CLUE-Tech] Bash and password entry

Jeffery Cann fabian at jefferycann.com
Sat Mar 30 08:21:45 MST 2002


Oops.

I forgot to make my point, which is that this perl function calls shell utils 
to do the prompting, so you can extract it for your purposes.  I also forgot 
the important function, set_echo():

sub set_echo {
        my ($toggle) = @_;
        my $status;

    $status = system( "stty -echo" ) if $toggle eq 'OFF';
    $status = system( "stty echo" ) if $toggle eq 'ON';
    die "Error: Could not stty: $?\n" unless $status == 0;
}

On Saturday 30 March 2002 08:03, Jeffery Cann wrote:
> Matt,
>
> This perl function will do what you want.  It takes three parameters:
>
> 1.  The prompt text.
> 2.  The default response.
> 3.  Whether to echo the user's response.
>
> HTH.
>
> sub prompt {
>         my ($text,$default,$noecho) = @_;
>         my $reply;
>
>         set_echo('OFF') if $noecho;
>
>     if ($default) {
>                 print "$text [$default]: ";
>         } else {
>                 print "$text: ";
>         }
>
>         chomp( $reply = <STDIN> );
>         if ($noecho) {
>                 print "\n" if $noecho;
>                 set_echo('ON') if $noecho;
>         }
>
>     if ($reply) {
>             return $reply;
>         } else {
>                 return $default;
>         }
> }
>
> On Sunday 24 March 2002 13:37, Matt Gushee wrote:
> > Hi, all--
> >
> > I was wondering how you can handle password entry in a shell script.
> > I was thinking about writing a script that would synchronize certain
> > directories on 2 hosts, using scp ... obviously it would be nice not
> > to have to enter a password/passphrase for each file copied, but I
> > don't know how (or if) I could store a password in a variable and
> > reuse it.
> >
> > I now realize that for this particular problem the easiest and probably
> > best solution is just to run the script in an ssh-agent session. But
> > I've thought in the past about automating various tasks that involve
> > passwords, and there isn't always a convenient password-preserving
> > shell available. Is there a utility you can call from bash to handle
> > passwords?
>
> _______________________________________________
> CLUE-Tech mailing list
> CLUE-Tech at clue.denver.co.us
> http://clue.denver.co.us/mailman/listinfo/clue-tech



More information about the clue-tech mailing list