Please help me with my cron job. Immense details inside.

Installing, Configuring, Troubleshooting server daemons such as Web and Mail
Kinsbane
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Post by Kinsbane » 2010/01/27 19:59:22

Well, I found the solution, although it IS a bit weird!

I was reading this article:
http://net.tutsplus.com/tutorials/other/scheduling-tasks-with-cron-jobs/

And I noticed the part about the bracket ( > ) to write to a log file. I changed the PHP file to not have the hash-bang declaration in the beginning, and put the parser path in the cronjob line instead. So now, my cron job looks like this:
[code]
40 11 * * * /usr/bin/php /home/jshaw/retireevents.php >> /home/jshaw/cron.log
[/code]

And I just got an email from the PHP script, meaning it ran like it should!

I guess the cronjobber was looking for a bracket or two to signify the end of the file/path declaration.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: Please help me with my cron job. Immense details inside.

Post by pschaff » 2010/01/27 20:10:12

[quote]
Kinsbane wrote:
...
I guess the cronjobber was looking for a bracket or two to signify the end of the file/path declaration.[/quote]
Don't think that's the trick as I have never used redirection like that on the command line with cron, so it is definitely not required. Normally cron generates an email if and only if any output is produced. What you have done will redirect stdout to append to the log file. Anything going to stderr should still result in an email from cron to the owner of the crontab. If you want stderr to go to the log, append 2>&1 to the line.

I expect the real trick had something to do with getting rid of the shell script, but that's strange because I frequently use shell scripts (sometimes with redirection inside the script) with cron. Does the following work?[code]40 11 * * * /usr/bin/php /home/jshaw/retireevents.php[/code]?

michaelnel
Posts: 1478
Joined: 2006/05/29 16:50:11
Location: San Francisco, CA

Re: Please help me with my cron job. Immense details inside.

Post by michaelnel » 2010/01/27 20:23:10

Glad it's working for you! I don't think it was the redirect to a log file that made it work, but it's still great that the problem is solved.

User avatar
AlanBartlett
Forum Moderator
Posts: 9345
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk
Contact:

Re: Please help me with my cron job. Immense details inside.

Post by AlanBartlett » 2010/01/28 15:31:31

I'm seconding [b]Michael[/b]'s & [b]Phil[/b]'s comments.

With luck, after all the scratching, I've still got some "head fur" left. :roll:

Post Reply