我对设置cronjobs并不陌生,我正尝试在Google计算引擎中的虚拟机上进行设置。经过一番研究,我发现了这个StackOverflow问题:在虚拟机(Google云平台)中使用Cron定期运行Python脚本
I am new to setting up cronjobs and I'm trying to do it on a virtual machine in google compute engine. After a bit of research, I found this StackOverflow question: Running Python script at Regular intervals using Cron in Virtual Machine (Google Cloud Platform)
根据答案,我设法输入了 crontab -e 编辑模式并设置测试cronjob,例如 10 8 * * * / usr / bin / python / scripts / kite-data-pull / dataPull.py 。我还检查了系统时间(以UTC为单位),并据此输入了时间。
As per the answer, I managed to enter the crontab -e edit mode and set up a test cronjob like 10 8 * * * /usr/bin/python /scripts/kite-data-pull/dataPull.py. I also checked the system time, which was in UTC, and entered the time according to that.
按照答案,我应该采取的步骤是运行 sudo systemctl restart cron 正在向我抛出错误:
The step I'm supposed to take, as per the answer, is to run sudo systemctl restart cron which is throwing an error for me:
sudo systemctl restart cron System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down关于我该怎么做的任何建议
Any suggestions on what I can do to set up this cronjob correctly?
推荐答案使用 crontab -e 并插入一行:
* * * * * echo test123> /your_homedir_path/file.log
这将每分钟将 test123 写入文件。日志文件。
That will write test123 every minute into file.log file.
然后在 tail if 做,然后等待几分钟。您应该看到 test123 行出现在文件(和屏幕)中。
Then do tail if and wait a couple minutes. You should see test123 lines appearing in the file (and screen).
如果运行,请尝试运行python文件但首先请使用 chmod + x script.py
If it runs try running your python file but first make your .py file executable with "chmod +x script.py"
在这里,您可以找到我对类似问题的答复。
Here you can find my reply to similar question.
更多推荐
在Google Compute Engine上设置cronjob
发布评论