2

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?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • Try do delete your venv and create a new one – ofirule Dec 04 '20 at 23:33
  • 1
    Have you checked the ` /var/mail/` to see if there are any other errors with the previous commands? Have you tried using `&&` instead of `;` to ensure that the python script will not run if the previous commands fail? – Flair Dec 09 '20 at 08:20

3 Answers3

2

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.

Dave
  • 15,639
  • 133
  • 442
  • 830
0

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

bastien-p1
  • 34
  • 4
  • Hi ,Yes I enabled +x (775) but still get the error. I would prefer not to enable 777 perms. – Dave Dec 04 '20 at 13:16
  • It's just a supposition, but can the error come from the bash execution ? In this case, it might works by putting your commands in a ```.sh``` file, then running this file from cron (with a ```chmod 755``` on this one too). – bastien-p1 Dec 04 '20 at 23:04
0

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.