2

Sumary

I have a similar problem with cron.daily jobs not running, but the solutions there do not apply to me.

I have setup a script that should run daily through cron.daily. I placed my script in the /etc/cron.daily. When the computer is on all night, the script executes normally. However, from my understanding of anacron, if I turn off the computer and turn it on (even after the time the cron.daily runs normally), anacron should run the scripts that didn't run in the standard time. But, for some reason, anacron is not triggering everyday, and it works on some days and in others it doesn't.

Details

From the community documentation it seems that anacron should be running daily on startup

So it appears anacron is run on every startup, wake up, plug-in, and at 7:30 AM every day. Looking at the respective Changelogs and package databases, it looks like this setup is directly from Debian, and hasn't been changed since at least 2009.

but it isn't.

I tested by switching the laptop on after the time of the anacron schedule, 7:30 AM, but it is not working. At first, I thought it was skipping days but I don't know where to search for that configuration, as I didn't change its behavior.

If you need any logs let me know, I can provide them.

Logs

/etc/log/syslog

$ cat /var/log/syslog | grep cron
Mar 10 09:40:36 computer anacron[798]: Job `cron.daily' terminated
Mar 10 09:40:36 computer anacron[798]: Normal exit (1 job run)
Mar 10 10:17:01 computer CRON[26842]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 11:17:01 computer CRON[27296]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 12:17:01 computer CRON[28337]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 13:14:01 computer CRON[28761]: (root) CMD (   test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond)
Mar 10 13:17:02 computer CRON[28779]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 14:00:48 computer systemd[1]: Started Run anacron jobs at resume.
Mar 10 14:17:01 computer CRON[30881]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 15:17:01 computer CRON[31557]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 17:19:19 computer systemd[1]: Started Run anacron jobs at resume.
Mar 10 18:17:01 computer CRON[2100]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 19:17:01 computer CRON[2745]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 10 20:17:01 computer CRON[3475]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 09:33:19 computer cron[918]: (CRON) INFO (pidfile fd = 3)
Mar 13 09:33:19 computer cron[918]: (CRON) INFO (Running @reboot jobs)
Mar 13 10:17:01 computer CRON[9045]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 11:17:01 computer CRON[13534]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 12:17:01 computer CRON[20925]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 13:14:01 computer CRON[21354]: (root) CMD (   test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond)
Mar 13 13:17:01 computer CRON[21377]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 14:17:01 computer CRON[22770]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Mar 13 15:17:01 computer CRON[24406]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

Non-filtered log for the first hours of the system on 10/03 and 13/03.

adn
  • 261
  • Please edit your question to show your /var/log/syslog during a time when your script runs successfully, and a time when it doesn't run. – user535733 Mar 13 '17 at 18:33
  • I dumped the syslog from 10 when it ran, and 13 when it didn't. I filter it through cron let me know if you need the whole thing or another filter. – adn Mar 13 '17 at 18:39
  • No filter - we want to see the trigger (like cron.hourly) and the job running, then the same trigger and the job not running. There's usually a helpful error message in sylog when a job fails...or we'll see that the trigger didn't run. – user535733 Mar 13 '17 at 18:44
  • Added the logs. I put the first hours as there is too much data for pastebin to handle. Let me know if you need other hours I can add them. – adn Mar 13 '17 at 19:14
  • @user535733 any hints from the logs? – adn Mar 14 '17 at 17:15
  • cron.daily runs before 9:40 am. One of it's jobs is to...rotate the logs. If your task is triggered by cron.daily, you should show us the previous log(s) when all the cron.daily activity occurs. So far, everything looks normal. – user535733 Mar 14 '17 at 17:31
  • The logs start when the computer is turned on. The log before that is the last log of the day before. That is my problem, the computer is turned off, and when I turn it on, anacron should run, but it is not. And if I left the computer on all night, then when cron triggers the cron.daily it executes normally. Not sure what is going on. – adn Mar 14 '17 at 17:46
  • Basics: Do you have the anacron package installed? Do you have /etc/init.d/anacron ? That file is how anacron runs at boot. – user535733 Mar 14 '17 at 18:05
  • yes to both questions – adn Mar 14 '17 at 19:35
  • When you boot, are other cron.daily jobs running? If so,the problem is in your script. If not, reinstall anacron. – user535733 Mar 15 '17 at 01:21
  • My script runs if I left the computer on, so the script should not be the problem. As for the other scripts in cron.daily, I'm not sure where they store their logs. Will try to search for those. And the anacron is the one that comes default with the system. – adn Mar 15 '17 at 13:25
  • If the logs start when the computer is powered on AND logs start if left powered on, then cron.daily is running under both circumstances, and cron/anacron seem both working properly. Does your job require services or resources that are may not available immediately after boot? Like network or display? Have you added logging to your job? – user535733 Mar 15 '17 at 13:35
  • It needs some resources, but from my understanding anacron executes 5 minutes after startup, not immediately after. And, yes I have log. And there is no information there. Even if the script is executed, I should see error messages there. But there is none. So, it seems like the script is not executed at all. – adn Mar 15 '17 at 13:46
  • Gather data - explicitly confirm whether or not your script is running: Add a hearbeat log entry to the beginning and end of your script. Add another cron.daily job that runs immediately before your script and makes a log entry. Add another cron.daily job that runs immediately after your script and makes a log entry. – user535733 Mar 15 '17 at 13:54
  • But anacron is not running as sudo cat /var/spool/anacron/cron.daily shows still that it was last executed on 10/03. And I have the heartbeats you mentioned on my script and still nothing. I will test with other scripts, but I thing the issue is with the configuration of anacron itself. – adn Mar 15 '17 at 14:56
  • That's why I suggested reinstalling anacron. – user535733 Mar 15 '17 at 17:50
  • 1
    not sure this is still relevant. came across this while configuring anacron myself. looking at my (default) /etc/init.d/anacron script it only starts anacron when -not- running on battery power (assuming it is able to determine this). so that then triggers the question if you were running on battery power on days where anacron did not execute :)? – Kees Beets Jul 13 '17 at 11:27
  • Good question. I will observe if that is the case. It didn't occur to me to check it. – adn Jul 13 '17 at 16:53

1 Answers1

0

Addendum: I may have to eat some crow here. It appears that, even with the removal of the don't-do-it-while-on-battery command cron.daily is still not executing reliably on this laptop. The search resumes.


I had noticed that anacron wasn't running the daily jobs on my good laptop, yet ran reliably on two ancient ones. After several months of noodling around I stumbled across the answer. This applies to laptops only.

There's a file in /etc/cron.daily called 'app-compat'. Near the end of that file are these lines:

# ensure we don't do this on battery  
check_power || exit 0

I commented out the check_power line to permit cron.daily to run while on battery.

This newer laptop has a good battery and I almost never use it while plugged into the charger. The other two old ones are always plugged in since their batteries are in poor shape. So cron.daily ran on the old machines but not on the new one.

NotTheDr01ds
  • 17,888
Don Karon
  • 276
  • 2
  • 4