You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Operation not permitted when running a script from crontab

Hello!


I have a problem that I bash file run from cron gives ”bash: operation not permitted”.

In crontab I have:

19,34 * * * * /Users/rickiekaveby/Documents/perl/uah/fix_uah.sh >/tmp/stdout.log 2>/tmp/stderr.log


When the script has run from crontab /tmp/stderr.log looks like this:

/bin/bash: /Users/rickiekaveby/Documents/perl/uah/fix_uah.sh: Operation not permitted


The script start with

#!/bin/bash


Running the script in terminal is working ok:

cd /Users/rickiekaveby/Documents/perl/uah; ./fix_uah.sh

Rickies-MacBook-Pro:uah rickiekaveby$


The script creates some files in /Users/rickiekaveby/Documents/perl/uah

I have added full disk access for bash and terminal, so that’s not the problem. 


Thankful for any hint!


Rickie

MacBook Pro 15″, macOS 12.6

Posted on Jan 6, 2023 1:08 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 8, 2023 5:10 AM

In the Full Disk Access preferences, click on the + icon


press: Command-Shift-Period


This will show hidden files in file select dialog window.


navigate to the directory with cron


select cron


You press the Command-Shift-Period keys again to toggle the showing of hidden files so they are hidden again.

6 replies

Jan 6, 2023 5:54 AM in response to rickiefromstockholm

It sounds like whatever user is running the Cron job does not have access to your documents, folder. bash and Terminal are not the users in this case.


I don’t use cron, so I’m not sure, but I think cron runs as root, and root probably doesn’t have access to your Desktop, Documents, and Downloads folder per Ventura’s privacy model.

You may be able to set it up to run as your user, but that’s beyond my knowledge of cron.

Does the script run on files in your Documents folder? If not, you could move them to a location that root can access. I would avoid trying to give root access to the Privacy protected folders.

Jan 8, 2023 2:16 AM in response to Barney-15E

I made a new crontab for the user rickiekaveby. I thought it worked since there was no /tmp/stderr.log created. However I found that the script did not work, but now it couldn't create a file in /tmp.

Modifying the cron job to write log in the same directory as the script run in showed that still gives ”bash: operation not permitted”.

Operation not permitted when running a script from crontab

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.