Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux debian crontab job not executed [duplicate]

I have a bash script foo.sh located in the /etc/cron.daily directory, chmoded 700, owned by root, crontab list for the root user is unchanged (crontab -l) from the core Debian installation. I did run cronjob in another way than crontab -l and/or crontab -e (eg I did not restart cron daemon with /etc/init.d/cron as adviced in the specific Debian's case). Despite a test job file is running under similar conditions. The script is debugged and can be run as a standalone task without returning errors. I've also checked logs (/var/log/syslog) and nothing wrong in there.

But: this particular job is not executed at all.

like image 519
hornetbzz Avatar asked Mar 30 '11 12:03

hornetbzz


2 Answers

Oops. Guess I found the "why" or at least, the "how" :

Only renaming the job filename without ".sh" extension solved that issue.

I thought it was a Debian's bug but it isn't, as described in the other answers below.

SOLUTION: rename your script by removing all . or + characters from its name

like image 103
hornetbzz Avatar answered Nov 01 '22 03:11

hornetbzz


the /etc/cron.daily scripts are executed by run-parts (see man 8 run-parts).

there you go with a snip from the manpage:

If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens.

from /etc/crontab you can see that the daily cron jobs are being run with:

25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

debian doesn't use anacron and there's no --lsbsysinit option specified for run-parts (in that case '.' will be accepted in the cron script filename as per the LSB hierarchical and reserved namespaces)

anyway, to make sure cron will run your script you can always run run-parts and check that your script is listed in the run-parts output:

run-parts --test /etc/cron.daily

or

run-parts --list /etc/cron.daily

I hope my comment helps you understand what the real problem was.

like image 23
user237419 Avatar answered Nov 01 '22 03:11

user237419