问题
I am trying to run a python script in my Google VM Instance using Cron jobs.
- My script is supposed to log some data from a website and stores it in a CSV file. I tried running it using the usual
python3 kb_sc.py
and it worked just fine.
... #scrap the website
print("checkpoint")
if not (os.path.isdir(path)):
os.makedirs(path)
if not (os.path.isfile(path + file)):
data_new.to_csv(path+file, index = False)
else:
data = pd.read_csv(path+file)
data = data.append(data_new)
data.to_csv(path+file, index = False)
print("done")
- I enlisted it using
sudo crontab -e
and entered the scheduling as* * * * * cd /home/[myusername] && python3 kb_sc.py
- I made sure my script was executable using
sudo chmod +x kb_sc.py
- I made sure CRON is running using
sudo service cron status
- I also even added
> kb.log
at the end of the CRON command* * * * * cd /home/[myusername] && python3 kb_sc.py
to find out if it prints thecheckpoint
anddone
message. Thekb.log
file is created but it is empty.
Many other similar questions have been asked but it does not help, like 1, 2
I do not know what else is causing this issue, much less solving in.
来源:https://stackoverflow.com/questions/56139973/python-script-using-cron-job-not-saving-output-to-file-in-google-vm-instance