Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

perl - Why does my command-line not run from cron?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...