在 Google Compute Engine 上设置 cronjob

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

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

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

发布评论

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

>www.elefans.com

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