user2032654
user2032654

Reputation: 51

Cronjob cron.daily does not run (debian)

I got a script to run daily at any time. So /etc/cron.daily seems to be an easy solution.

But now I got the problem, the cronjob won't run that script. It seems like the cronjob won't run any of the daily jobs.

So I tried to put it to cron.hourly and everything worked fine. But I dont want to run the backup script every hour.

/etc/init.d/cron start|stop works without errors.

/etc/crontab looks like default:

 m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report     /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

As it won't run I tried to install anacron but without any changes.

Why does it run the hourly scripts but not the daily ones?

Many thanks to all of you!

Upvotes: 5

Views: 12603

Answers (8)

Digdilem
Digdilem

Reputation: 50

Debian, unlike the EL distros, only runs files in these dirs that do not have an extension.

So anything with a .sh or .pl extension will not be run.

You can test and verify this but running run-parts --test -v --report /etc/cron.daily first, then renaming one of your .pl or .sh scripts, then re-running

(Thanks to other commenters who helped me trace this)

Upvotes: 0

Alexander Stumpf
Alexander Stumpf

Reputation: 116

In my case I had two issues that caused the very same problem:

  1. The script had a dot in the filename (script.sh) and run-parts wouldn't run that script. Renaming it to just script got me a step further.
  2. run-parts complained about an incorrect executable format (or similar). Adding the shebang (like #!/bin/bash) at the beginning of the file solved that as well.

Upvotes: 1

Geremia
Geremia

Reputation: 5656

I had this problem, and it was because the owner of my script in /etc/cron.daily was not root. Make root the owner of all the scripts in /etc/cron.daily:

sudo chown root /etc/cron.daily/*

Also, be sure the scripts are executable:

sudo chmod +x /etc/cron.daily/*

Upvotes: 3

Michael S
Michael S

Reputation: 880

I had the same problem with one of my scripts in /etc/cron.daily The name of the script was backupBugzilla.sh

After renaming the script to backupBugzilla it worked.

Upvotes: 6

rasta
rasta

Reputation: 11

I have a wheezy not start the /etc/init.d/anacron.

My solution:

edit /etc/init.d/anacron

Required-Start: $all

save and run:

update-rc.d /etc/init.d/anacron defaults

now works well when wheezy start.

Upvotes: 1

emdete
emdete

Reputation: 41

the manpage of run-parts states:

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

I assume it does not like the name of your script. for example it does not like the extension ".sh" as a dot is not allowed.

Upvotes: 4

Leo Tulipan
Leo Tulipan

Reputation: 320

It might be, that one of your daily-scripts is misbehaving. Try running them manually. I removed the logwatch package and the cron.daily job and it worked again.

This is my /etc/crontab

# /etc/crontab: system-wide crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
16 * * * * root cd / && run-parts --report /etc/cron.hourly
12 2 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
41 1 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
9 3 30 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

try running the daily like so

 run-parts -v --report /etc/cron.daily

you can also use --list or --test for more output. In my case I removed the misbehaving script and the daily job worked again

Upvotes: 6

christophrus
christophrus

Reputation: 1180

Do you have anacron installed?

# dpkg --get-selections | grep anacron

If yes, it doesn't runs the daily, weekly and monthly scripts.

Upvotes: 3

Related Questions