cronjobs do not run
Solution 1:
I'd recommend a couple of things:
- Make sure
cron
has Full Disk Access in the Privacy tab ofSystem Preferences
(see s/s below)
- When creating commands in
crontab
, help yourself out by writing errors generated bystderr
to an output file using2>&1
, and using full pathnames (yourcron
job does not run w/ same environment as your user does);
EXAMPLE:
seamus@Dung-Pro ~ % crontab -l
*/5 * * * * /usr/bin/touch /Users/seamus/scripts/cronjob-success-"$(date)".txt
SOME OTHER IDEAS:
-
crontab guru: https://crontab.guru/
-
not always necessary, but using full path to command is a good habit!
-
it often helps to re-direct
stderr
(aka2
) to a file for review when things go wrong -
re-direct may be done as follows:
>> /home/pi/cronjoblog 2>&1
This redirects
stdout
to/home/pi/cronjoblog
and redirectsstderr
tostdout
; i.e. both streams will be written to the file.
Finally, wrt the specific command in your question: that does not run for me either - it has something to do with the formatting specified for the date
command - date
with no formatting works fine. If you need that specific command to run under cron
, I'll need to do some debugging - let us know. Otherwise, the info above may help get you started.
Solution 2:
- grant permissions for cron and possible the terminal apps / command line tools to run on Catalina.
- check for full paths everywhere...
- consider putting your commands in a script so you can debug them and avoid needing to escape characters like % or run
cron
in debug/test mode