Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Twig in a crontab?

by BenHopkins (Sexton)
on Jan 31, 2008 at 03:18 UTC ( #665272=perlquestion: print w/ replies, xml ) Need Help??
BenHopkins has asked for the wisdom of the Perl Monks concerning the following question:

I have this little program:
lauxastst01:~/bin:cat test.pl #!/usr/bin/perl -w use strict; use Date::Manip qw(UnixDate); use XML::Twig; print "OK!\n";
When I run it from the command line, it outputs OK! When I run it as a cron job, it outputs this:
Can't load '/usr/local/perl/5.8.2/lib/site_perl/5.8.2/sun4-solaris/aut +o/XML/Parser/Expat/Expat.so' for module XML::Parser::Expat: ld.so.1: +perl: fatal: libexpat.so.0 : open failed: No such file or directory at /usr/local/perl/5.8.2/lib/ +5.8.2/sun4-solaris/DynaLoader.pm line 229. at /usr/local/perl/5.8.2/lib/site_perl/5.8.2/sun4-solaris/XML/Parser. +pm line 14 Compilation failed in require at /usr/local/perl/5.8.2/lib/site_perl/5 +.8.2/sun4-solaris/XML/Parser.pm line 14. BEGIN failed--compilation aborted at /usr/local/perl/5.8.2/lib/site_pe +rl/5.8.2/sun4-solaris/XML/Parser.pm line 18. Compilation failed in require at /usr/local/perl/5.8.2/lib/site_perl/5 +.8.2/XML/Twig.pm line 98. BEGIN failed--compilation aborted at /usr/local/perl/5.8.2/lib/site_pe +rl/5.8.2/XML/Twig.pm line 98. Compilation failed in require at ./test.pl line 4. BEGIN failed--compilation aborted at ./test.pl line 4.
It complains about Expat.so, which, I guess is required by Parser.pm, which, I guess is required by XML::Twig. Notice that I included a 'use' for Date::Manip before XML::Twig to show that it is not incapable of finding all modules, just that it can't find XML::Twig in the crontab environment. What gives?

Comment on Twig in a crontab?
Select or Download Code
Re: Twig in a crontab?
by TOD (Friar) on Jan 31, 2008 at 04:37 UTC
    does cron run the job as root? if it doesn't check the file permissions on Expat.so
    --------------------------------
    masses are the opiate for religion.
Re: Twig in a crontab?
by Fletch (Chancellor) on Jan 31, 2008 at 04:48 UTC

    Not that it's strictly speaking a perl problem, but processes run from cron don't run with the same environment as your normal login shell sets up. Look in your .profile / .bashrc / whatnot for environment variables such as LD_LIBRARY_PATH and what not and either add those to your cron command line, write a shell wrapper which sets them then runs your perl, or set them in a BEGIN block in your code (e.g. BEGIN { $ENV{LD_LIBRARY_PATH} = q{...}; }).

    Failing that, find your local sysadmin and they'll probably be able to tell you what needs to be set.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      You're probably right. I have LD_LIBRARY_PATH set to (among other things) /usr/sfw/lib, where libexpat.so lives.

      The bad news is that I've tried both a BEGIN block and setting in the crontab, but neither works.

      I even did this in the crontab file:

      45 21 * * * LD_LIBRARY_PATH=/usr/sfw/lib ; echo $LD_LIBRARY_PATH; cd b +in; ./test.pl

      and got this:

      Your "cron" job on lauxastst01 LD_LIBRARY_PATH=/usr/sfw/lib ; echo $LD_LIBRARY_PATH; cd bin; ./test.p +l produced the following output: /usr/sfw/lib Can't load '/usr/local/perl/5.8.2/lib/site_perl/5.8.2/sun4-solaris/aut +o/XML/Parser/Expat/Expat.so' for module XML::Parser::Expat: ld.so.1: +perl: fatal: libexpat.so.0 : open failed: No such file or directory at /usr/local/perl/5.8.2/lib/ +5.8.2/sun4-solaris/DynaLoader.pm line 229.

      Sigh ... I'll keep trying stuff until it works.

        You can set environment variables at the beginning of the crontab file; cron will automatically export these to your script's environment. Like so:
        LD_LIBRARY_PATH=/usr/sfw/lib


        If you want to improve, be content to be thought foolish and stupid. -- Epictetus
        Just FYI, this is what made it work. I ran a shell script from the cron. It looks like this:

        #!/bin/sh LD_LIBRARY_PATH=/usr/sfw/lib export LD_LIBRARY_PATH chdir $HOME/bin ./test.pl

        Maybe if I put the export command in the crontab line it would have worked, but it gets real messy when you jam too much stuff in the crontab file.

Re: Twig in a crontab?
by hipowls (Curate) on Jan 31, 2008 at 07:18 UTC

    One answer is to use crle which has a similar function to ldconfig on linux

    # show current config crle # create new config crle -l /usr/lib:/usr/local/lib:/opt/swf/lib crle -u
    will create a configuration file for the linker so that it knows where to look for dynamic libraries.

    Warning Read the man page before running any commands.

      Of course, the next closest thing is to just create symlinks in /usr/lib to the expat library ;-)

      (I know new symlinks are needed each time you upgrade the expat library. I know that this will happen so infrequently that you'll need to reinvestigate each time it happens because you won't remember. Shhhh!)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-07-29 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (225 votes), past polls