Cron job not running in OSX 10.14.6 Mojave

My domain is: video2.streamlms.net

My web server is (include version): Apache/2.4.34 (Unix)

The operating system my web server runs on is (include version): OSX 10.14.6 (Mojave)

I can login to a root shell on my machine (yes or no, or I don’t know): Yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): No

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): 0.37.1

I installed a cert on the above site (since renewed manually today), but the cron job, which should have run ten days ago, didn’t run.

I reentered the command to set up the cron job (I had also done this back in September), per the instructions:

echo “0 0,12 * * * root python -c ‘import random; import time; time.sleep(random.random() * 3600)’ && certbot renew” | sudo tee -a /etc/crontab > /dev/null

This should add the cron job to the crontab, but that doesn’t appear to be happening. I’m prompted for an admin password, and everything seems fine … no error message. But when I subsequently run

sudo crontab -l

… the system replies that there are no crontab jobs for root. Same when I check the admin user’s crontab.

The file with specifications for the renewal IS created, in the /etc/letsencrypt/renewal/ directory, and the contents of that file look good. But the cron job doesn’t run, probably because, for some reason, it’s not getting added to the crontab.

Any suggestions? Renewing with sudo certbot renew worked fine, renewing the certificate with no errors. I’m just hoping not to have to manually do that every couple of months (I know … first world problems). I considered whether giving all files access in Mojave’s security to /usr/sbin/cron might be needed (homebrew needs it), but even if that’s the case, shouldn’t something be showing up when I run sudo crontab -l ?

Also, I checked the letsencrypt logs … no activity logged at all between Sept 2, when I first set this up, and today when I manually renewed. No messages about failed renewal attempts, or even any renewal checking.

Thanks for any advice.

1 Like

Can you use crontab -e to edit cron list?

Otherwise, try this approach.

Step 1. Create a bash file with these contents (change “admin” for your actual “root user ID”):

#!/bin/bash
newcronline="<<<your job details>>>"
(crontab -u admin -l; echo "$newcronline" ) | crontab -u admin -
crontab -u admin -l

Step 2. Make the new bash file executable (chmod).

Step 3. Execute the new bash file.

1 Like

/etc/crontab is different from “root’s crontab” in current Unix systems. Per-user crontabs—even root’s—are probably all kept somewhere under /var. Also, /etc/crontab may have a different syntax from a per-user crontab because it may have an additional field indicating the username.

I think @rg305’s answer correctly points at the importance of using the crontab program to edit crontabs, rather than using tee.

Thank you, I’ll try those suggestions!

Note, however, that the instructions for installing Certbot on Apache may need to be changed, as I was following those instructions. See: https://certbot.eff.org/lets-encrypt/osx-apache

The instructions do seems a bit of a faux pas.
It should be reviewed and updated (if needed).

FYI, the (evidently incorrect) instructions are still there under https://certbot.eff.org/lets-encrypt/osx-apache

How do we bring this to the attention of someone who can correct them?