How do I restore my Python cron jobs after my Mac OS upgrade?

Viewed 480

I recently upgraded to Mac Big Sur and have noticed my Python 3.8 cron jobs have stopped working. Under my own account in a bash shell, I can run this without issues ...

davea$ cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python3 manage.py check_duplicates 

In my crontab, I had this set up, which used to work before the upgrade ...

*/5 * * * * /bin/bash -l -c 'cd /Users/davea/Documents/workspace/article_project; source ./venv/bin/activate; python manage.py check_duplicates >> /Users/davea/logs/record2.txt 2>&1'

However, after the upgrade, I'm noticing my command is never run and I see this issue in my log file

/Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'manage.py': [Errno 1] Operation not permitted

These are the permissions/groups on my "manage.py" file ...

davea$ ls -al manage.py 
-rwxrwxr-x 1 davea staff 866 Apr 15  2019 manage.py

What else do I need to do to get my cron job to run again?

3 Answers

Turns out with the new Mac OS there is an extra level of permissions that need to be enabled. In System Preferences, under Security and Privacy, I clicked the Privacy tab, and then added "cron" to the "Full disk Access" list

enter image description here

then the cron jobs ran without the permissions error.

I think in this case, python3 is considered as "any user" and with the -rwxrwxr permission it only have right to read the file, try to run chmod 775 manage.py in your folder to add permission to manage.py to be executed by "any user" (rigths should be set to -rwxrwxr), hope it can help. EDIT: technically, read permission should be enough for python to run a file, but I can't see another reason why this error would appear, and I would be interested if you find one

This looks like a SIP or other mac-specific access permissions error, especially since it was right after an upgrade. Could be: https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/

I've also had lots of problems working with venvs with cron, could be related to this: https://stackoverflow.com/a/7031758/13113166

It's also weird that the error comes from /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 when i think it should come from your venv if it's activated correctly.

Related