M BUZZ CRAZE NEWS
// general

My cron jobs aren't running when trying to save the script output to a txt file

By Joseph Russell

I am trying to have a python script run twice a day- once at 8:00 AM and again at 8:00 PM. My hope was to store the script output to a txt file on my computer named LOG_{date-time}.txt so I could look at "log" files in case something went wrong with the script. I set up the following cron job:

0 8,20 * * * python3 /script/working/directory/Script.py > /script/working/directory/logs/LOG_"$(date +"%d-%m-%Y")".txt

After setting up the cron job I checked the script after 8:00 PM and noticed my script hadn't run yet (I have it set to update a spreadsheet file and leave a time stamp after each update).

I did a bit of troubleshooting on my own and found that if I ran the cron job without the output portion of it, it would work (I also found that the cron job logs are put out in UTC instead of my system time, but that is an issue for another time):

0 8,20 * * * python3 /script/working/directory/Script.py

Is there something I'm missing here? Shouldn't this store the scripts output to a file? I am a bit new to things here and have been trying to learn as I go with this but I'm just not sure where to go with this. It would be nice to be able to store the outpupt of my script for debugging purposes.

4

1 Answer

The main reason I can assume is either the log path doesn't exist or you don't have permission to write to the log path.

Try executing the command manually instead of the cron

python3 /script/working/directory/Script.py > /script/working/directory/logs/LOG_"$(date +"%d-%m-%Y")".txt

You will most likely see the error in your terminal.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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