[英]How do I restore my Python cron jobs after my Mac OS upgrade?
I recently upgraded to Mac Big Sur and have noticed my Python 3.8 cron jobs have stopped working.我最近升级到 Mac Big Sur 并注意到我的 Python 3.8 cron 作业已停止工作。 Under my own account in a bash shell, I can run this without issues...
在我自己的 bash shell 帐户下,我可以毫无问题地运行它...
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...在我的 crontab 中,我进行了这个设置,它在升级之前可以工作......
*/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...这些是我的“manage.py”文件中的权限/组...
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?我还需要做什么才能让我的 cron 工作再次运行?
Turns out with the new Mac OS there is an extra level of permissions that need to be enabled.事实证明,新的 Mac OS 需要启用额外级别的权限。 In System Preferences, under Security and Privacy, I clicked the Privacy tab, and then added "cron" to the "Full disk Access" list
在系统偏好设置的安全和隐私下,我点击隐私选项卡,然后将“cron”添加到“全盘访问”列表中
then the cron jobs ran without the permissions error.然后 cron 作业在没有权限错误的情况下运行。
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.我认为在这种情况下,python3 被视为“任何用户”,并且具有
-rwxrwxr
权限,它只有读取文件的权限,尝试在您的文件夹中运行chmod 775 manage.py
以添加要执行的manage.py
权限由“任何用户”(rigths 应设置为-rwxrwxr
),希望它可以提供帮助。 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编辑:从技术上讲,读取权限应该足以让 python 运行文件,但我看不出出现此错误的另一个原因,如果你找到一个我会感兴趣的
This looks like a SIP or other mac-specific access permissions error, especially since it was right after an upgrade.这看起来像是 SIP 或其他特定于 mac 的访问权限错误,尤其是因为它是在升级之后。 Could be: https://osxdaily.com/2018/10/09/fix-operation-not-permitted-terminal-error-macos/
可能是: 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我在使用 cron 使用 venv 时也遇到了很多问题,可能与此有关: 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.错误来自
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
也很奇怪,而我认为如果正确激活它应该来自您的 venv。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.