ap1997
ap1997

Reputation: 183

Trying to run a Python script with cron, getting [Errno 1] Operation not permitted

So I have a Python script which just pulls information from APIs and sends an email. When I run it manually, it works. I have a cron job set up:

30 7 * * * /Users/myname/anaconda3/bin/python3 /Users/myname/Desktop/repo/somefolder/script.py >> /Users/myname/Desktop/filename.log 2>&1

but the output in filename.log is: /Users/myname/anaconda3/bin/python3: can't open file '/Users/myname/Desktop/repo/somefolder/script.py': [Errno 1] Operation not permitted

I've tried lots of different things involving trying out different file permissions, creating the cron job as root, adding a shebang, and different Python paths, but cannot get any output other than this error. Nothing I've found online has given a different result so far.

I'm using macOS Catalina 10.15.1. The file permissions currently for my script:

-rwxr--r--  1 myname  staff  4161 13 Nov 18:07 /Users/myname/Desktop/repo/somefolder/script.py

Any help would be appreciated!

Upvotes: 4

Views: 1839

Answers (1)

Eric Adams
Eric Adams

Reputation: 93

I had a very similar issue with attempting to run a node.js script using crontab in MacOS. In order for me to finally get it to work, I had to add cron and zsh to the Full Disk Access in my Security and Privacy settings in System Preferences.

How to add cron: 1. Apple Menu -> System Preferences -> Security & Privacy -> Full Disk Access 2. Click the Lock to Allow Changes 3. Click the + Sign 4. hit Command + Shift + G and in type '/usr/sbin/' 5. scroll to find "cron" in the list of binaries 6. Click "Open"

How to add zsh: 1. repeat steps 1 - 3 2. hit Command + Shift + G and in type '/bin' 3. scroll to find "zsh" in the list of binaries 4. Click "Open"

After I did that my cron jobs ran without issue. Hope that helps

Upvotes: 7

Related Questions