I wrote a Python script which backs up mongoDB, and it works fine when I test run directly in terminal.
However, I get an error from cron saying mongodump: command not found
- although the command mongodump
works fine when I run the script directly in terminal.
Contents of crontab -e
:
* * * * * cd <path-to-script> && python3 script.py
After looking into the post provided by S3DEV's.
Running the full env path of mongodump into the python script worked. To get the full path of mongodump, in terminal:
which mongodump
>>/usr/local/bin/mongodump
In my case i am using os.system() in my script.
os.system(/usr/local/bin/mongodump [commands])
instead of
os.system(mongodump [commands])