[CLUE-Tech] Bash and password entry
Jeffery Cann
fabian at jefferycann.com
Sat Mar 30 08:03:42 MST 2002
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?
More information about the clue-tech
mailing list