Why does my command-line not run from cron?
cron, environment-variables, perl, shell
Solution
It's often because you don't get the full environment when running under cron. Best bet is to capture the ouput by using the command:
( /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1
and then have a look at `/tmp/qq`.
If it does turn out to be a missing environment, then you may need to put:
. ~/.profile
or something similar, into the execution chain of your cron job, such as:
( . ~/.profile ; /sw/bin/perl /path/to/tv_grab_oztivo ... ) >/tmp/qq 2>&1
Problem
I have a perl script (part of the XMLTV family of "grabbers", specifically `tv_grab_oztivo`). I can successfully run it like this: ``` /sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml ``` I use the full paths to everything to eliminate issues with the Working Directory. Permissions shouldn't be a problem. So, if I run it from the Terminal (Mac OSX) it works just fine. But when I set it to run via a cron job, nothing appears to happen at all. No output is created etc. There isn't anything wrong with the crontab as far as I can see, because if I substitute a helloworld.pl for the actual script, it runs just fine at the right time. So, what can I do to debug? I can see from looking at `%ENV` in the two cases that the environment is very different, but what other approaches can I take to debugging? How can I see the output of the cron job, which might be some kind of perl "die" message or "not found" message from the shell or whatever? Or should I be trying to somehow give the cron version of the command the same environment as when it's running as me?