Search code examples
pythonbashshellcron

Python script Permission Denied from shell script when invoked from Crontab


I have to schedule some tasks for which I invoke a shell script in my home directory. I try to run a python script from this Shell script but it doesn't work.

I have tried the following till now.

  1. I have validated that Crontab does invoke the shell script by echoing from the shell script to an output file
  2. I ran the shell script independently from the terminal and it executes the python script successfully
  3. I have added the shell script to chmod and also the python script

Shell script code

#!/bin/sh

python3 /absolute path/to/file/myfile.py >> log_script.txt


Solution

  • I was finally able to solve this question thanks to get the good suggestion provided here https://www.bejarano.io/fixing-cron-jobs-in-mojave/, cron needs to be provided disk access, it seems, it doesn't have disk access by default, as a side not make sure to also allow terminal to have full disk access

    Simply add the following to full disk access under,

    System Settings > Privacy & Security > Full Disk Access

    /usr/sbin/cron