0

The server perl script - with its required packages - works locally by the user "my_user".

But if I run the script remotely (ssh), I need to export PERL5LIB=/usr/local/share/perl/5.10.0/my_modules before calling the perl script to get it working.

Why this and how can I turn around this in order to avoid exporting PERLIB each time I need to call a remote perl script ?

WORKING :

ssh my_user@remote_server "export PERL5LIB=/usr/local/share/perl/5.10.0/my_modules; /cgi-bin/my_perl_script.pl --option1 foo --option2 '*';"  

NOT WORKING :

ssh my_user@remote_server "/cgi-bin/my_perl_script.pl --option1 foo --option2 '*';"  

returns : Can't locate my_package1.pm in @INC

That might be rather an ssh question than a strict perl point : why the remote user running the perl script does not inherit from its ENV local datas.

Thx

hornetbzz
  • 9,188
  • 5
  • 36
  • 53
  • 1
    Non-interactive shells don't use the same configuration as interactive ones: http://stackoverflow.com/questions/216202/why-does-an-ssh-remote-command-get-fewer-environment-variables-then-when-run-manu/216204#216204 – mu is too short Feb 21 '11 at 18:28
  • 1
    On the remote system, which `perl` is being invoked by the script? and what do you see from `/perl -V`, compared to the output of your local perl? You shouldn't need *any* environment variables to run a perl script, locally or remotely, if it has been set up properly. – Ether Feb 21 '11 at 19:09
  • @Ether: thx for the comment : if I run /usr/bin/perl -V locally (on the remote machine), I have my lib path /usr/local/share/perl/5.10.0/my_modules included in @INC, but not if I run ssh my_user@remote_server "/usr/bin/perl -V" despite this is the same single perl bin. – hornetbzz Feb 21 '11 at 21:40
  • @mu: yep I guess this is the point I worked around somehow intituively (interactive shell when login/non interactive shell when ssh). I have never figured this out at all (I'm a big noob, still learning all by doing). Thank you. – hornetbzz Feb 21 '11 at 21:50
  • @hornet: what do you mean "the same single perl bin" -- aren't you using a totally separate system to run the remote request? Unless they share a filesystem e.g. NFS, these are totally separate perl installations, and the required packages may not be installed there. – Ether Feb 22 '11 at 01:37
  • @Ether: I run a perl script hosted on a server. This server includes perl (here on this server, I meant a single perl version). I run this script from another machine via ssh. – hornetbzz Feb 22 '11 at 01:45

1 Answers1

1

As suggested by @mu_is_too_short (no friction is good as well), and linking to a more detailed explanation here, there are different types of shells : "the SSH command execution shell is a non-interactive shell, whereas your normal shell is either a login shell or an interactive shell".

So the solution is what I did on purpose (eg adding "export PERL5LIB" before running the script), or better, source the whole environement from the remote user to run the remote shell with the expected behavior.

Community
  • 1
  • 1
hornetbzz
  • 9,188
  • 5
  • 36
  • 53