tekka has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have an environment where a perl script is called from inside a shell script.
The shell script starts ssh-agent and ssh-add so that environment variable SSH_AUTH_SOCK is set.
I would like to use that environment variable from inside the called perl script.
My ssh key has a passphrase set and so my goal would be to be able to talk to the ssh-agent from inside the perl script; this way I will be prompted for passphrase (not password) only once when running ssh-add in the shell script while some rdist subcommands that are inside the perl script will not ask for passhprase any more but talk directly to ssh-agent setup previously.
If I had to do this all in shell script (so a shell script that calls another shell script) I can reach this goal calling the inner shell script with something like:
env SSH_AUTH_SOCK=$SSH_AUTH_SOCK inner_script.sh
The same doesn't work ootb if the inner is a perl script.

I found on the web about Net::SSH::Perl::Agent that seems to be the thing for me but I don't understand how to use it (I'm a very beginner in perl and the perl script is not totally under my control...) to be able to inherit the env SSH_AUTH_SOCK and use it to automatically talk with the ssh- agent.
Any hints/example?
I don't know if this makes any difference, but the way my rdist commands are called inside the perl script is something like:

my $command="rdist $RDIST_OPTIONS"; open(RDIST, "$command 2>&1 |" ) || die("$basename: Unable to open $command\n"); my $errorcount = 0; while ( <RDIST> ) { ... some other commands/conditional statements ... }
So I would like the rdist command not to ask for passhprase for every host it has to process...

Thanks in advance,
Gianluca

Replies are listed 'Best First'.
Re: How to talk to ssh-agent from inside a perl script
by Khen1950fx (Canon) on Mar 05, 2010 at 10:14 UTC
    Here's an ssh-agent-setup perl script.
Re: How to talk to ssh-agent from inside a perl script
by salva (Canon) on Mar 05, 2010 at 10:44 UTC
    env SSH_AUTH_SOCK=$SSH_AUTH_SOCK inner_script.sh

    Why are you doing this instead of just exporting the variable (export SSH_AUTH_SOCK)? Which shell are you using?

      You are right; actually there was a part inside the perl script that zeroed the SSH_AUTH_SOCK env var in certain cases... that I met... ;-(

      So it was a false problem.

      Thanks anyway for the help and for the ssh-agent script.