I have the following entry in crontab -e, which is supposed to run a python script every day at 11 am and dump the output to log.txt:

0 11 * * * /usr/bin/python3 /var/www/folder/python/script.py > /var/www/folder/python/logs/log.txt

The log.txt file is being consistently created, but nothing is being written to it. As far as I can tell, the python script is not being run at all despite working correctly when run from the terminal directly.

Is there something wrong with my cron syntax or is it something else I could be missing?


Since /var/www/folder/python/logs/log.txt is being created, that means the shell redirection is occurring as you would expect, so it does seem to be executing the command, albeit unsuccessfully. You can have it send its stderr to the log as well by modifying your cron entry to:

0 11 * * * /usr/bin/python3 /var/www/folder/python/script.py > /var/www/folder/python/logs/log.txt 2>&1

You might want to check /var/mail/$USER as well; there might be informative stderr output there if it's behaving differently than when you run /usr/bin/python3 /var/www/folder/python/script.py manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.