Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Setting a library path (export) to call SSH

by Spaceman_Spiff65 (Initiate)
on Jul 08, 2013 at 19:49 UTC ( #1043174=perlquestion: print w/replies, xml ) Need Help??
Spaceman_Spiff65 has asked for the wisdom of the Perl Monks concerning the following question:

By no means am I even remotely conversant in Perl, but we have several modules in our Unix (AIX) environment from a previous mad monk perl coder that our team needs to maintain. We are in the process of migrating from RSH to SSH as our means of remotely executing shell scripts on remote systems. The use of SSH in a shell script requires us to do an export: export LIBPATH=/opt/freeware/lib:/opt/freeware/64/lib:/usr/lib:$LIBPATH How can I replicate this in a Perl script? Currently our Perl script calls rsh via the following: `rsh remotesys -l uid /apps/lbin/ prod`; Any thoughts or suggestions would be appreciated!
  • Comment on Setting a library path (export) to call SSH

Replies are listed 'Best First'.
Re: Setting a library path (export) to call SSH
by OfficeLinebacker (Chaplain) on Jul 08, 2013 at 19:57 UTC
    I think what you have to do is set an environment variable from within perl, which you can do quite easily. There is a special hash variable called %ENV that you set like this:
    $ENV{LIBPATH} = "/opt/freeware/lib:/opt/freeware/64/lib:/usr/lib:$ENV{ +LIBPATH}";
    Best of luck!

    (Note that using backticks to do something like `export LIBPATH=/opt/freeware/lib:/opt/freeware/64/lib:/usr/lib:$LIBPATH` launches a shell, sets the environment variable in that shell, then quits, which doesn't do you much good.)

      You can, if you _really_ must encapsulate the setting environment into the 'backticks'.

      my $result = `set LIBPATH=/opt/freeware/lib:/opt/freeware/64/lib; ssh +$host stuff`;

      It's probably better to configure %ENV though. Any may be better yet to fix your library paths though - ssh is something that'd probably benefit from being 'properly installed' into the environment. Maybe even by replacing your ssh binary (in your path) with a wrapper script, in /usr/bin or similar. It may be worth doing a (non packaged) install of ssh, so you can install your own libs in the right places.

      Or to isolate the LIBPATH setting to just where needed...

      { local $ENV{LIBPATH} = "/opt/freeware/lib:/opt/freeware/64/lib:/usr/l +ib:$ENV{LIBPATH}"; # execute ssh command here }


        Thank you all for the wisdom and suggestions, much appreciated!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1043174]
Approved by OfficeLinebacker
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2018-02-25 22:21 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (315 votes). Check out past polls.