Search code examples
macosunixcron

Operation not permitted while trying to run script through crontab - Mac


I am trying to run a MongoDB backup script in the crontab (MacOS Catalina 10.15.6)

*/2 * * * * cd ~/Documents/MongoDB/hourly/ && source hourly_m_backup.sh >/tmp/stdout1.log 2>/tmp/stderr1.log

I am getting the error

/bin/sh: hourly_m_backup.sh: Operation not permitted

The details for the files:

-rwxrwxrwx@ 1 Sethu  staff  686 11 Sep 19:38 hourly_m_backup.sh

I went through a lot of StackOverflow posts. I couldn't get the script to run through crontab. But if I execute the script independently from the terminal, it's working. I even deleted the file and created a new file. Still, I am getting errors from CronTab. Not sure what to do anymore.

------------ Update --------------

I tried running with sudo command

*/1 * * * * echo "####" | sudo -S cd ~/Documents/MongoDB/hourly/ && echo "####" | sudo -S source hourly_m_backup.sh >>/tmp/stdout1.log 2>>/tmp/stderr1.log

I am getting the error

sudo: source: command not found

-----------Update ----------

I tried the solution from this post, and I implemented this solution

*/1 * * * * echo "####" |  source <(sudo -S cat ~/Documents/MongoDB/hourly/hourly_m_backup.sh) >>/tmp/stdout1.log 2>>/tmp/stderr1.log

I am getting this error in the "mail"

/bin/sh: -c: line 0: syntax error near unexpected token (' /bin/sh: -c: line 0: echo "####" | source <(sudo -S cat ~/Documents/MongoDB/hourly/hourly_m_backup.sh) >>/tmp/stdout1.log 2>>/tmp/stderr1.log'


Solution

  • The solution is a bummer. I have to provide Full Disk Access to CRON in Mac.

    enter image description here