Search code examples
pythonbashunixcron

Crontab, python script fails to run


I have a bash script to automate few things I do. The bash calls 2 python scripts, If I run the bash script normally, everything runs, no errors what so ever. I set up a cron job to Automate this and when I checked the logs I noticed the python scripts don't run at all. It gives me the following error.

python: can't open file 'movefiles.py': [Errno 2] No such file or directory

python: can't open file 'create_log_shimmer.py': [Errno 2] No such file or directory

Both these files exist and runs when calling the bash script directly.


Solution

  • The working directory of the cron is different from the directory you run the script directly.

    • Make your bash script to use absolute path for python script files.

    • Or make the bash script to change directory to where you run the script directly.