Cron Job does not get executed

5 posts / 0 new
Last post
#1 Tue, 05/26/2009 - 23:38
horch004

Cron Job does not get executed

In PHP I create a file with a cronjob. Then I use exec('crontab <filename>') to install the job. This works fine. The job is listed within WebMin->System->Scheduled Cron Jobs.

The only problem is: the job never gets executed.

When I edit the job from within WebMin, change nothing but save it immediately, the job is getting executed fine. Suprise me!

When I look at cron-lib.pl, which is used from save_cron.cgi saving the job from within WebMin, the key difference might be that it seems jobs are pushed onto a cron_jobs_cache array.

My guess is that cron uses the cache and that the crontab command installs the job but does add the job to the cache. So, the new job never gets executed.

Is this the right conclusion? And above all, is there a solution to get the job activated to run on it's schedule from PHP?

Wed, 05/27/2009 - 00:14
Joe
Joe's picture

<div class='quote'>When I look at cron-lib.pl, which is used from save_cron.cgi saving the job from within WebMin, the key difference might be that it seems jobs are pushed onto a cron_jobs_cache array.</div>

You're conflating two different things. Webmin and the cron-lib.pl are <i>not</i> cron, and nothing you see there has any relation to what happens when cron runs. Webmin isn't running cronjobs. It is editing them. Your problem is with the PHP script or the cronjob is produces. Look at it directly in the crontab (edit the crontab with &quot;crontab -e&quot;, and see what's weird about it.

--

Check out the forum guidelines!

Sun, 06/07/2009 - 07:56 (Reply to #2)
horch004

&amp;*(&amp;*&amp;^*#%##!!!!! Oh men... I examined the crontab file my script produced and the crontab file WebMin produced (I did it before, but did not found a difference). Now I did. The only difference was a \n at the end of the job line. In other words: there has to be a \n at the end of the job line. Without it the job is not executed (probably not seen). With the \n it does the job. Shoot, what a little nifty difference. This costed me hours.

Thanks Joe for narrowing the problem to the crontab file.

Sun, 06/07/2009 - 07:56 (Reply to #3)
horch004

&amp;*(&amp;*&amp;^*#%##!!!!! Oh men... I examined the crontab file my script produced and the crontab file WebMin produced (I did it before, but did not found a difference). Now I did. The only difference was a \n at the end of the job line. In other words: there has to be a \n at the end of the job line. Without it the job is not executed (probably not seen). With the \n it does the job. Shoot, what a little nifty difference. This costed me hours.

Thanks Joe for narrowing the problem to the crontab file.

Wed, 05/27/2009 - 01:04
horch004

It does not show up right in the post, but the difference I mention is a &lt;return&gt; at the end of the line.

Topic locked