【问题标题】:Cron in AWS Elastic Beanstalk to fire js fileAWS Elastic Beanstalk 中的 Cron 来触发 js 文件
【发布时间】:2020-08-07 09:44:39
【问题描述】:

我试图在 AWS Elastic Beanstalk 环境中的 CRON 中每分钟触发 js 文件。然而,该文件永远不会被触发。

这是我的 EB cron 配置。我把它放在.ebextensions 并命名为cron-linux.config

files:
  "/etc/cron.d/mycron":
    mode: "000644"
    owner: root
    group: root
    content: |
       * * * * * root /usr/local/bin/myscript.sh

  "/usr/local/bin/myscript.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash

      date > /tmp/date     // inside here I can see actual date so cron works 

      node ./var/app/current/scripts/testCrobJob.js     //this file is not fired

      exit 0

commands:
  remove_old_cron:
    command: "rm -f /etc/cron.d/mycron.bak"

我怎样才能让它工作?

【问题讨论】:

    标签: amazon-web-services cron amazon-elastic-beanstalk


    【解决方案1】:

    运行此代码的修改版本以创建一个文件。

    文件: ./.ebextensions/cron-linux.config

    files:
      "/etc/cron.d/mycron":
        mode: "000644"
        owner: root
        group: root
        content: |
           * * * * * root /usr/local/bin/myscript.sh
    
      "/usr/local/bin/myscript.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
          #!/bin/bash
    
          date > /tmp/date     // inside here I can see actual date so cron works 
    
          node /tmp/test.txt     // <----- THIS WAS CREATED
    
          exit 0
    
    commands:
      remove_old_cron:
        command: "rm -f /etc/cron.d/mycron.bak"
    

    您可能需要删除多余的点 a 开头,因为这会将目录设置为 ./var 与根 /var 路径的相对路径。

    如果您可以通过 SSH 连接到机器并在其中手动运行该代码,您应该能够看到错误。

    潜在解决方案:

          node /var/app/current/scripts/testCrobJob.js
    

    【讨论】:

    • @murakami 让我知道这是否是答案,以便我们将其标记为正确。如果没有,请告诉我,以便我尝试调试它。
    猜你喜欢
    • 2012-01-10
    • 2015-09-02
    • 2017-04-20
    • 2013-04-11
    • 2021-12-30
    • 2019-10-17
    • 2015-04-06
    • 2016-11-25
    相关资源
    最近更新 更多