【问题标题】:CRON in Google Cloud ShellGoogle Cloud Shell 中的 CRON
【发布时间】:2018-05-18 21:43:54
【问题描述】:

下面我附上了/包括我输入“crontab -l”时得到的内容命令,并使用crontab -e 进行了编辑。

我使用过THIS QUESTION'S ANSWERS - 但这并没有完全解决问题。我对编程并不陌生,但我不知道有“堆栈溢出”经验的人期望什么。请单击上面的链接以查看建议的内容。我已按照指示进行操作,但这并没有让我的 CRON 工作运行......我已经问了另外两个问题(尝试使用 Java Servlet)关于让这行 Java 代码每天被调用一次。我需要在每天上午 11:15 运行一行 Java 代码,大约需要一个小时才能完成。除了调用 GSUTIL 将文件复制到存储桶之外,它不会调用任何 Google 云服务。

如果有人知道我在 20 年前所做的 GCS 上的 CRON 作业 - 请阅读我附上的输出,并解释我如何让这两个脚本执行:

# This runs an hour of Chinese & Spanish Translation jobs
java -cp /home/rtorello75/etc/Torello.jar Torello.GCS.Main.DispatchCRON

# This is just my "feeble minded attempt" to make this work.
# It produces a "TEST.txt" file with a timestamp in my ~/home directory
java -cp /home/rtorello75/etc/Torello.jar Torello.GCS.CRON.Test

第一个是我的主要代码模块,第二个“Torello.GCS.CRON.Test”只是将一个测试字符串转储到一个测试文件@(显然)下午 5:12,现在就是这样。这实际上并没有发生......

有什么帮助吗?我正在尝试让 CRON 作业运行/执行。

rtorello75@dispatch-cron:~$ crontab -l
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
15 11 * * * java -cp /home/rtorello75/etc/Torello.jar Torello.GCS.Main.DispatchCRON 
12 17 * * * java -cp /home/rtorello75/etc/Torello.jar Torello.GCS.CRON.Test  
# m h  dom mon dow   command

【问题讨论】:

    标签: java cron google-cloud-platform


    【解决方案1】:

    首先:要知道人们需要什么来帮助你,假装你是我们,对这个问题的背景一无所知。基本上,SO 不是一个讨论论坛,因此来回可能会很痛苦,您希望提供尽可能多的信息。您在 vm 或 GKE 作业中运行它?

    其次:除此之外,我能回答的最好的办法就是简化问题:Java 是一个复杂的命令,所以至少要检查是问题所在,还是您的 cron 选项卡,甚至是您的 cron 设置。使用许多在线 crontab 解析器之一来确认您在选项卡文件中的计划字符串是正确的,然后使用 ls 或 cat 之类的简单命令而不是 Java。

    【讨论】:

      【解决方案2】:

      您的 cron 选项卡看起来不错。除此之外,您还没有提供任何 Java 代码、堆栈跟踪或类似代码,我可以说这不会在 Cloud Shell 中运行。

      在您链接的answers 之一中,已经说过 Cloud Shell 旨在以交互方式使用。 Non-interactive versions will be terminated,这意味着您的 cronjob 可能会执行,也可能不会执行。

      这里的最佳选择是 other user 所建议的,基本上就是将此任务移动到 Compute Engine 中的一个实例。有一个非常有用的quickstart here 可以帮助您开始。

      【讨论】:

        猜你喜欢
        • 2018-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-21
        • 2023-03-29
        • 1970-01-01
        • 2020-04-08
        相关资源
        最近更新 更多