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?

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.

You’re conflating two different things. Webmin and the cron-lib.pl are not 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 “crontab -e”, and see what’s weird about it.

It does not show up right in the post, but the difference I mention is a <return> at the end of the line.

&(&&^*#%##!!! 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.

&(&&^*#%##!!! 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.