Why is my command line not starting from cron?

I have a perl script (part of the XMLTV family of "grabbers" in particular tv_grab_oztivo).

I can successfully run it as follows:

/sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml

I use full paths to everything to fix working directory problems. Permissions should not be a problem.

So, if I run it from the terminal (Mac OSX), it works fine.

But when I set it to run through cron, nothing happens at all. No output is created, etc.

There is nothing wrong with crontab as far as I can see, because if I substitute helloworld.pl for the actual script, it works fine at the right time.

So what can I do for debugging? I can see, looking at %ENVin two cases, when the environment is very different, but what other approaches can I take for debugging? How can I see the result of the cron job, which may be some kind of perl "dying" message or a "not found" message from the shell or something else?

Or should I try to somehow give the cron version of the command in the same environment as when working with it?

+5
source share
5 answers

This is often because you do not get a complete environment when working under cron. The best bet is to capture an exit using the command:

( /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1

and then take a look at /tmp/qq.

, :

. ~/.profile

- , cron, :

( . ~/.profile ; /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1
+8

% ENV , , perl script % ENV , cron, . , :

BEGIN {
  if (exists $ENV{something_in_your_env_not_in_cron}) {
     %ENV = (...);
     exec $^X, $0, @ARGV;
  }
}

, -, ( perl -d, ). , , % ENV , (LD_LIBRARY_PATH , ORACLE_HOME DB2HOME Oracle DB2 ). script crontab.

+3

script cron. script , stdout stderr ( ) . . Unix cron - MacOS X. PATH. .cronfile, , - .profile.

0

, , , - script. , .

: /files/cron1.sh

#!/bin/sh
/sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml

cron:

/files/cron1.sh

script cron. , , cron.

0

cron stdout stderr crontab.

crontab, , ?

, script . (bash) script, , script.

-1

All Articles