Koozali.org: home of the SME Server

Cron job not running?

Offline DanB35

  • *****
  • 764
  • +0/-0
    • http://www.familybrown.org
Cron job not running?
« on: December 11, 2015, 03:58:33 PM »
I'm sure I'm missing something simple on this, but I'm starting to go in circles, and not making any progress.  I'm trying to set up a cron job to run a letsencrypt.org certificate renewal.  I've created a template fragment for /etc/crontab following the instructions at http://wiki.contribs.org/Cron_entry, and the template fragment contains this:
Code: [Select]
48 22 10 */2 * root /opt/letsencrypt-renew.sh
...which, unless I'm totally misreading everything I've read about cron, should run /opt/letsencrypt-renew.sh as root on the 10th of every other month, at 22:48.  Thus, it should have run last night--but it didn't.

I've expanded the crontab template, and that line appears in /etc/crontab.  I've restarted crond.  /opt/letsencrypt-renew.sh exists and is root-executable.

There's nothing in /var/log/cron at 22:48.  There are entries from 22:45, and entries from 22:50, but nothing from 22:48:
Code: [Select]
Dec 10 22:45:01 e-smith CROND[29765]: (root) CMD (/usr/bin/clamav-unofficial-sigs.sh &>/dev/null)
Dec 10 22:45:01 e-smith CROND[29767]: (root) CMD (/usr/bin/php  /usr/bin/horde-alarms)
Dec 10 22:45:01 e-smith CROND[29768]: (root) CMD (/bin/nice /sbin/e-smith/awstats-pp -s -n)
Dec 10 22:45:01 e-smith CROND[29766]: (www) CMD (scl enable php56 'php -f /home/e-smith/files/ibays/owncloud/html/cron.php > /dev/null 2>&1')
Dec 10 22:50:01 e-smith CROND[30210]: (root) CMD (/bin/nice /sbin/e-smith/awstats-pp -s -n)
Dec 10 22:50:01 e-smith CROND[30211]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Dec 10 22:50:01 e-smith CROND[30212]: (root) CMD (/usr/bin/php  /usr/bin/horde-alarms)

What should I be looking at to track this down?
......

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Cron job not running?
« Reply #1 on: December 11, 2015, 05:44:16 PM »
Code: [Select]
48 22 10 */2 * root /opt/letsencrypt-renew.sh
...which, unless I'm totally misreading everything I've read about cron, should run /opt/letsencrypt-renew.sh as root on the 10th of every other month, at 22:48. 

not on every month, just every 2 months IIUC


Offline DanB35

  • *****
  • 764
  • +0/-0
    • http://www.familybrown.org
Re: Cron job not running?
« Reply #2 on: December 11, 2015, 06:04:13 PM »
Yes, every two months--or in months divisible by two, which this month is.
......

Offline brianr

  • *
  • 990
  • +2/-0
Re: Cron job not running?
« Reply #3 on: December 11, 2015, 06:50:21 PM »
How do you know it did not run?
Brian j Read
(retired, for a second time, still got 2 installations though)
The instrument I am playing is my favourite Melodeon.
.........

Offline DanB35

  • *****
  • 764
  • +0/-0
    • http://www.familybrown.org
Re: Cron job not running?
« Reply #4 on: December 11, 2015, 06:58:11 PM »
My first clue was when I was not emailed any output.  My second (and, I think, definitive) indication was that there's no indication in /var/log/cron of it running.  My third indication is that my server is still using the cert issued on 8 Dec.
......

Offline brianr

  • *
  • 990
  • +2/-0
Re: Cron job not running?
« Reply #5 on: December 11, 2015, 07:34:46 PM »
My first clue was when I was not emailed any output.  My second (and, I think, definitive) indication was that there's no indication in /var/log/cron of it running.  My third indication is that my server is still using the cert issued on 8 Dec.

Suggest you manufacture another entry in the Cron file which you can spot exactly that it has run or not.

Also please show the contents of /etc/crontab.
Brian j Read
(retired, for a second time, still got 2 installations though)
The instrument I am playing is my favourite Melodeon.
.........

Offline DanB35

  • *****
  • 764
  • +0/-0
    • http://www.familybrown.org
Re: Cron job not running?
« Reply #6 on: December 11, 2015, 08:21:18 PM »
Suggest you manufacture another entry in the Cron file which you can spot exactly that it has run or not.
The output of cron jobs is emailed to admin, correct?  I get email with the output of other cron jobs, when they generate output; this one would have generated output, but did not result in an email.

Cron commands are logged in /var/log/cron when run, correct?  There are lots of entries in /var/log/cron, but nothing at the time called for by this entry.

Finally, there's the matter that the desired outcome of the cron entry (i.e., my TLS certificate being renewed) did not happen--but that could be due to an error in the script or any number of other issues (which is why I'm trying to test it).

Am I correctly understanding you to be questioning whether the command actually ran?  If so, wouldn't at least the first two paragraphs above be definitive that it didn't?  Or is one of the assumptions in those two paragraphs incorrect?

But for the sake of testing, I changed the entry to
Code: [Select]
0 14 11 * * root /opt/letsencrypt-renew.sh...and it ran.  I saw it come up in /var/log/cron, and I got an email with the result of the script.  So, either */2 isn't working properly, or it isn't doing what I think it should be doing (to wit, running in the months divisible by two--Feb, Apr, Jun, etc.).  I expect the latter is the more likely.

The answers at http://serverfault.com/questions/129633/how-to-run-cron-job-every-3-months-in-apache2 do suggest that I'm understanding the */2 expression incorrectly (as Stefano suggested, but I believed to be incorrect), and suggest that */2 for the month would result in running in Jan, Mar, May, etc.  Seems a little unintuitive to me, but if that's the way it works that isn't too hard to plan for.
......

Offline brianr

  • *
  • 990
  • +2/-0
Re: Cron job not running?
« Reply #7 on: December 11, 2015, 09:05:46 PM »
http://www.pantz.org/software/cron/croninfo.html

Says that:

"Step values can be used in conjunction with ranges. Following a range with "/" specifies skips of the number's value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2"."

Is it that Jan is "0" not "1"?

Brian j Read
(retired, for a second time, still got 2 installations though)
The instrument I am playing is my favourite Melodeon.
.........

Offline DanB35

  • *****
  • 764
  • +0/-0
    • http://www.familybrown.org
Re: Cron job not running?
« Reply #8 on: December 11, 2015, 09:32:00 PM »
No, 'man 5 crontab' indicates that the valid values for the month are 1-12, so January would have to be 1, not 0.  The manpage really isn't very clear about how this works, but (with the benefit of a little experience), I'd now read "Following a range with "/" specifies skips of the number's value through the range" as it will start by matching the first value in the range, then skip by n.  For months, the range is 1-12, so 1-12/2 (or */2, which would be equivalent) will match 1, skip by 2, match 3, skip by 2, match 5, etc.  That also explains why */15 for the minutes in my owncloud cron job runs on the hour.

Edit:  If I really wanted Feb, Apr, Jun, etc., I guess I could use 2-12/2 for the month.
« Last Edit: December 12, 2015, 01:11:28 PM by DanB35 »
......