在Google Compute Engine上设置cronjob

编程入门 行业动态 更新时间:2024-10-25 16:23:31
本文介绍了在Google Compute Engine上设置cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对设置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

本文发布于:2023-10-07 12:46:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Compute   Google   cronjob   Engine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!