在 Google Compute Engine 上设置 cronjob [英] Setting up a cronjob on Google Compute Engine

查看:29
本文介绍了在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆