in reply to Re: Twig in a crontab?
in thread Twig in a crontab?

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.

Replies are listed 'Best First'.
Re^3: Twig in a crontab?
by sids (Acolyte) on Jan 31, 2008 at 06:22 UTC
    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.

        Then call a script instead.

        #!/bin/ksh LD_LIBRARY_PATH=.... export LD_LIBRARY_PATH cd /dir/where/you/want/to/start exec commandtorun param1 param2 ...

        Update: Added exec - saves one process in the process table.

        and call it from your crontab instead of the command you are calling right now.

        You can also do on the crontab line

        0 0 * * * LD_LIBRARY_PATH=foobar commandtorun param1 param2

        Also make certain that you have your CWD properly accounted for from cron. I will often do a cd /dir/to/run/from && command... as part of my cron line.

        --MidLifeXis

Re^3: Twig in a crontab?
by BenHopkins (Sexton) on Jan 31, 2008 at 07:31 UTC
    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.