in reply to Twig in a crontab?

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.

Replies are listed 'Best First'.
Re^2: Twig in a crontab?
by BenHopkins (Sexton) on Jan 31, 2008 at 05:56 UTC
    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
        That may be true for Linux or OS-X, but not for Solaris, which is what I'm working on.
      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.

        Bourne-ish shell syntax lets you set an environment variable for a single command by prefixing the command with VAR=value, so this command line would probably work if you wanted to do it in-place in the crontab:

        sh -c 'cd $HOME/bin ; LD_LIBRARY_PATH=/usr/sfw/lib ./test.pl'

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