Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Just another Perl shrine
 
PerlMonks  

cron vs bash (solved)

by dorko (Parson)
on Jun 04, 2010 at 14:05 UTC ( #843128=perlquestion: print w/ replies, xml ) Need Help??
dorko has asked for the wisdom of the Perl Monks concerning the following question:

While not exactly a Perl question, I hope the members of the monastery will indulge me.

I've got a Perl script on a Solaris server that runs fine from an interactive command line. The script fails when run under cron. The use statements seem to succeed, because the script partially runs and does provide some correct output. The exact error message is 500 Can't locate object method "new" via package "LWP::Protocol::https::Socket" at /home/stella/reach/grades/modules/Vista/Sdk.pm line 333 I'm using LWP and HTTPS, but if Perl couldn't find the OpenSSL libraries, it would have given me a different kind of error, right?

My research leads me to believe this a problem with the environment variables not being the same in the shell vs cron. I've added code in a begin block to change the $ENV variable.

printenv results:

LC_MONETARY=en_US.ISO8859-1 TERM=vt100 SHELL=/bin/sh SSH_CLIENT=10.173.87.94 3688 22 LC_NUMERIC=en_US.ISO8859-1 SSH_TTY=/dev/pts/3 USER=reach LD_LIBRARY_PATH=/local/ssl/lib:/local/gnu/lib/:/local/lib/ PATH=/sbin:/local/gnu/bin:/usr/local/bin:/usr/sbin:/usr/bin:/etc:/usr/ +openwin/bin:/opt/SUNWspro/bin:/usr/ucb:/usr/ccs/bin:/usr/dt/bin:/usr/ +sfw/sbin:/usr/sfw/bin MAIL=/var/mail//reach LC_MESSAGES=C LC_COLLATE=en_US.ISO8859-1 PWD=/usr/local/lib/perl5/site_perl/5.10.1/Net EDITOR=pico TZ=US/Eastern PS1=\u@\h:\w$ SHLVL=1 HOME=/home/stella/reach LOGNAME=reach SSH_CONNECTION=10.173.87.94 3688 10.171.240.149 22 LC_CTYPE=en_US.ISO8859-1 LC_TIME=en_US.ISO8859-1 _=/usr/ucb/printenv OLDPWD=/usr/local/lib/perl5/site_perl/5.10.1/LWP/Protocol
$ENV. before I change it:
$VAR1 = { 'HOME' => '/home/stella/reach', 'LOGNAME' => 'reach', 'SHELL' => '/usr/bin/sh', 'TZ' => 'US/Eastern', 'PATH' => '/usr/bin:' };
$ENV. after I change it:
$VAR1 = { 'HOME' => '/home/stella/reach', 'LOGNAME' => 'reach', 'SHELL' => '/usr/bin/sh', 'LD_LIBRARY_PATH' => '/local/ssl/lib:/local/gnu/lib/:/local/ +lib', 'TZ' => 'US/Eastern', 'PATH' => '/sbin:/local/gnu/bin:/usr/local/bin:/usr/sbin:/us +r/bin:/etc:/usr/openwin/bin:/opt/SUNWspro/bin:/usr/ucb:/usr/ccs/bin:/ +usr/dt/bin:/usr/sfw/sbin:/usr/sfw/bin' };
Now obviously I didn't bring all the environment variable over into cron, but I can't see how some of them would make a difference.

Any thoughts or suggestions? As always, thank you for your time.

Cheers,

Brent

-- Yeah, I'm a Delt.

Comment on cron vs bash (solved)
Select or Download Code
Re: cron vs bash
by bart (Canon) on Jun 04, 2010 at 14:26 UTC
    Your @INC must be different. See what it contains in each case.

    You can see where the module was found in the case of the console, by dumping %INC (in particular, $INC{'LWP/Protocol/https/Socket.pm'}), for example in an END block.

Re: cron vs bash
by Anonymous Monk on Jun 04, 2010 at 14:39 UTC
      programatically setting the LD_LIBRARY_PATH did it for me. Specifically, the response by tye.

      Basically, it starts the script, then checks for the right environment variable. If it's not there, it modifies the enviroment, then restarts the script. Ugly, but it works.

      For posterity, it was LD_LIBRARY_PATH setting that needed tweaking.

      Cheers,

      Brent

      -- Yeah, I'm a Delt.
Re: cron vs bash
by JavaFan (Canon) on Jun 04, 2010 at 15:40 UTC
    Are you using a PERL5LIB environment variable? If so, make sure the processes you start from cron have access to this variable as well.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://843128]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-04-18 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls