我是设置 cronjobs 的新手,我正在尝试在 google 计算引擎中的虚拟机上进行设置.经过一番研究,我发现了这个 StackOverflow 问题:在虚拟机(谷歌云平台)中使用 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关于我可以做些什么来正确设置这个 cronjob 的任何建议?
Any suggestions on what I can do to set up this cronjob correctly?
推荐答案使用 crontab -e 编辑 cron 作业并插入一行:
Edit a cron jobs with crontab -e and inset a line:
* * * * * echo test123 >/your_homedir_path/file.log
这将每分钟将 test123 写入 file.log 文件.
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"使您的 .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
发布评论