-4

I often execute a Perl script, which I cannot change, and it requires password to be passed as a command line argument in plaintext. For example:

$> perl myscript.pl -host localhost -user someone -pass topsecret -id 1,2,3,4

Without changing the myscript.pl, is there a trick which would enable me to avoid the password from showing up on the screen and in the command history? I would love to simply pass -p and then get prompted for password later with echo off mode as happens with mysql command:

$> mysql -hlocalhost -usomeuser -p -- mydb
Enter password:

Or some trick that would change whatever I type to appear as asterisks, for example:

$> perl myscript.pl -host localhost -user someone -pass ***** -id 1,2,3,4

1 Answer 1

0

As if you cant change the script itself, you may create a shell script which would safely ask you for password and pass it to the perl script. It may look like this. The key feature is to read the variable in silent (read -s) mode

#!/bin/bash
echo -n "Enter password: "
read -s password
perl /path/to/script/myscript.pl -host localhost -user someone -pass $password -id 1,2,3,4

Then make it executable:

chmod +x ./new-script.sh

And then just run it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.