[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: cron doesn't run /etc/cron.d jobs why is that ?



On 12/25/05, Maxim Vexler <hq4ever@gmail.com> wrote:
> Hello list,
>
> For some reason, jobs defined in /etc/cron.d doesn't get picked up by
> cron, while jobs from /etc/cron.{hourly,daily,weekly,monthly} do !
>
> I have verified this by putting the following commands in /etc/cron:
>
> $ apt-show-versions cron
> cron/testing uptodate 3.0pl1-92
> $ ps aux  | grep cron
> root      1569  0.0  0.1   1880   948 ?        Ss   12:00   0:00 /usr/sbin/cron
>
> $ ls -la /etc/cron.d/testcron
> -rwxrwxrwx  1 root root 67 2005-12-25 13:47 /etc/cron.d/testcron
>
> $ cat /etc/cron.d/testcron
> */1  * * * *  root echo $(date "+%H%M%S") > /tmp/LastRunBy_cron.d
>
> $ ls -la /etc/cron.hourly/testcron
> -rwxr-xr-x  1 root root 281 2005-12-25 13:45 /etc/cron.hourly/testcron
>
> $ cat /etc/cron.hourly/testcron
> #!/bin/sh
> echo $(date "+%H%M%S") > /tmp/LastRunBY_cron.hourly
>
>
> I have also tried to touched /etc/crontab and even did a reboot to the system.
>
> After letting it run for 3 hours, here is the output :
>
> $ ls /tmp/Last*
> /tmp/LastRunBY_cron.hourly
> $ cat /tmp/LastRunBY_cron.hourly
> 171701
> $
>

Replying to myself :)

All was OK, the only thing that was wrong was my test syntax, it
appears that when using cron.d to run sh scripts the % character
should be escaped otherwise it gets interpreted as a newline [1].

After applying the above, the file looks like this
# cat /etc/cron.d/testcron
*/1  * * * *  root /bin/echo $(/bin/date "+\%H\%M\%S") > /tmp/LastRunBy_cron.d
# cat /tmp/LastRunBy_cron.d
064701

[1] : http://www.brandonhutchinson.com/crontab_errors.html

Thank you and happy new year.

--
Cheers,
Maxim Vexler (hq4ever).

Do u GNU ?

Reply to: