I've started a compute engine instance in Google Cloud, I created a folder called "python" in the main dir, and "one.py" in that dir. Than I pasted this into one.py:
from datetime import datetime
import os
a=datetime.now()
file_to_open = os.path.join(os.getcwd(), "raw_data.txt")
with open(file_to_open, "a+") as file_object:
file_object.seek(0)
data = file_object.read(100)
if len(data)>0:
file_object.write("\n")
file_object.write(str(a))
file_object.close()
So far, so good. Dates are being saved to the file.
Than I added this to cronetab:
crontab -e
...
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * python3 ~python/one.py
The cron job is working, I'm getting this outputs after running
grep CRON /var/log/syslog
Mar 21 11:33:01 instance-2 CRON[605]: (myname) CMD (python3 ~/home/python/one.py)
Mar 21 11:33:01 instance-2 CRON[604]: (CRON) info (No MTA installed, discarding output)
Mar 21 11:34:01 instance-2 CRON[647]: (myname) CMD (python3 ~/home/python/one.py)
Mar 21 11:34:01 instance-2 CRON[646]: (CRON) info (No MTA installed, discarding output)
I thought it might be sth with the root directory being in a different place so did find . raw_data.txt
there's only one, under ~python/
Can someone help me fix this? Why the cron job isn't saving the dates to the file?