Noob question here. I'm scheduling a cron
job for a Python script for every 2 hours, but I want the script to stop running after 48 hours, which is not a feature of cron
. To work around this, I'm recording the number of executions at the end of the script in a text file using a tally mark x
and opening the text file at the beginning of the script to only run if the count is less than n
.
However, my script seems to always run regardless of the conditions. Here's an example of what I've tried:
with open("curl-output.txt", "a+") as myfile:
data = myfile.read()
finalrun = "xxxxx"
if data != finalrun:
[CURL CODE]
with open("curl-output.txt", "a") as text_file:
text_file.write("x")
text_file.close()
I think I'm missing something simple here. Please advise if there is a better way of achieving this. Thanks in advance.