You bring your web app in a
- GitHub repo
- App Platform handles deployments and builds
- DNS, HTTPS, CDN, DDoS Mitigation, Vertical Scaling, Horizontal Scaling, and more.
Unable to execute a python script via crontab, but can execute it manually. What gives?
I’ve written a python script for python 2.7 - its main purpose is to search the directory that it is in for any CSVs that begin with “contact” and end in “.CSV” - it then parses those CSVs and makes some API calls to send the data elsewhere.
I’ve installed the dependancies either via pip or easy install successfully - this is proven by the fact that I can execute the script manually from with in the scripts folder on Digital Ocean by typing
Initially, the cron job executed the script, but came back with an error which alerted me to the fact that
glob weren’t installed by default, which prompted me to install
When I fixed this, nothing happened. No logs. No execution. No expected results.
I even tried executing the cron command on the command line:
/usr/bin/python /var/www/client_folder/my_python_script.py &> /var/www/client_folder/log.txt
This printed the expected output to the log file with no error.
In summary: My script works without error when manually executed, but for some reason the cron job is either not executing it, or finding it, or something.
I am accessing the crontab via
crontab -e, and this was my original command (i’ve set it for every minute just to test it out) - i’ve also confirmed that
/usr/bin/python is indeed where python lives:
* * * * * /usr/bin/python /var/www/client_folder/my_python_script.py &> /var/www/client_folder/log.txt
As an addendum, the python script itself has a chmod of 755 and the csv it’s looking at has a chmod of 644. I am logged in as root, and all of the files regarding this issue were created under root.
I have also tried adding root in the cron command itself, to no avail.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.×