Python script using Cron Job Not saving output to file in Google VM Instance

这一生的挚爱 提交于 2021-02-11 14:34:04

问题


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 the checkpoint and done message. The kb.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!