【问题标题】:Setting up a cronjob on Google Compute Engine在 Google Compute Engine 上设置 cronjob
【发布时间】:2020-09-23 04:07:36
【问题描述】:

我是设置 cronjobs 的新手,我正在尝试在谷歌计算引擎中的虚拟机上进行设置。经过一番研究,我发现了这个 StackOverflow 问题:Running Python script at Regular intervals using Cron in Virtual Machine (Google Cloud Platform)

根据答案,我设法进入crontab -e 编辑模式并设置了一个像10 8 * * * /usr/bin/python /scripts/kite-data-pull/dataPull.py 这样的测试cronjob。我还检查了系统时间,它是UTC,并据此输入时间。

根据答案,我应该采取的步骤是运行sudo systemctl restart cron,这对我来说是一个错误:

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 有什么建议吗?

【问题讨论】:

  • 你可以试试:“sudo service cron reload”或“/etc/init.d/cron reload”命令吗?
  • 我试过sudo service cron relead,它给了我这个输出[ ok ] Reloading configuration files for periodic command scheduler: cron.我会检查脚本是否在10分钟内运行
  • cronjob 没有运行,还有什么我可以尝试的吗?如果有帮助,我的脚本是用 python 3 编写的,如果我执行python dataPull.py,它就会运行
  • 你知道它是否有权限问题吗?检查权限。还要验证是否需要添加 sudo。

标签: linux google-cloud-platform cron google-compute-engine debian-buster


【解决方案1】:

使用 crontab -e 编辑 cron 作业并插入一行:

* * * * * echo test123 > /your_homedir_path/file.log

这将每分钟将test123 写入file.log 文件。

然后执行tail if 并等待几分钟。您应该会在文件(和屏幕)中看到 test123 行。

如果它运行,请尝试运行您的 python 文件,但首先使用“chmod +x script.py”使您的 .py 文件可执行

Here你可以找到我对类似问题的回复。

【讨论】:

  • 谢谢!我错过了通过运行chmod +x 命令使文件可执行的步骤
  • 感谢您的确认!很高兴我能帮忙:)
猜你喜欢
  • 2017-08-11
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 2019-01-31
  • 2018-03-19
  • 2014-09-06
相关资源
最近更新 更多