是否可以在Amazon Lightail实例上运行cron作业? [英] Is it possible to have cron job running on Amazon lightsail instance?

查看:65
本文介绍了是否可以在Amazon Lightail实例上运行cron作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Amazon Lightsail实例上设置定期作业,但是我找不到关于它的信息-仅关于Amazon EC2。

I would like to set up periodic jobs on an Amazon Lightsail instance, but I can find no information on it - only for Amazon EC2.

是否可以在lightail实例上发布cron作业,还是我需要更改为EC2?

Is it possible to issue cron jobs on a lightsail instance, or do I need to change to EC2?

推荐答案

要回答我自己的问题,只需8小时后:可以在Amazon Lightsail实例上发布cron作业

To answer my own question, just 8 hours later: It IS possible to issue cron jobs on Amazon Lightsail instances

以下是运行PHP脚本的有效示例:

Here is a working example of running a PHP script:


  1. 通过记录到您的Lightsail实例进入您的lightail帐户,然后单击使用SSH连接或使用SSH客户端(例如PuTTY)。

  2. 在/ home中创建一个名为 projects的文件夹/ bitnami /,并创建一个名为Hello World的简单.php文件:

  1. Connect to your Lightsail instance either by logging in to your lightsail account and clicking "Connect using SSH" or using a SSH client, such as PuTTY.
  2. Create a folder called 'projects' in /home/bitnami/ and create a simple .php file called Hello World:

<?php print("Hello World"); ?>


  • 使用命令 crontab -e 要访问文档,您可以在其中添加将作为计划的cron作业的行。

  • Use command crontab -e to access a document, from where you can add lines that will be your scheduled cron jobs.

    在文档上添加两行并添加换行符:

    Append two lines to the document AND ADD A NEWLINE:

    PATH=/usr/bin:/bin:/opt/bitnami/php/bin:
    * * * * * php -f /home/bitnami/projects/HelloWorld.php > /home/bitnami/projects/Out.put
    

    第1行添加了php到cron路径(Cron看到的路径与环境变量中给出的路径不同。键入:env并在控制台中按Enter键)。要查看为cron提供了哪些env变量,请将第2行替换为: * * * * * env> /tmp/env.output 并查看文件。 第2行是计划时间表。星号表示:每小时,每天,每月,每年的每一分钟都要执行此操作。在Google上搜索:)并将其输出到名为 Out.put 的文件。

    Line 1 adds php to the cron path (Cron sees a different path than what is given in the environment variables. Type: env and hit enter in the console). To see which env variables are given to cron replace line 2 with: * * * * * env > /tmp/env.output and look in the file. Line 2 is the cron schedule. The asterisks means: Do this every minute of every hour, day, month, year. Search Google for this :) And will output to a file called Out.put.

    等待1分钟,然后看到 Out.put 已创建,并且包含 Hello World

    Wait 1 minute and see that Out.put has been created and contains the magic words of Hello World

    如果您在执行cron作业时遇到问题,请查看此故障排除指南: https://stackoverflow.com/tags/cron/info

    If you are having problems with cron jobs not working, check out this troubleshooting guide: https://stackoverflow.com/tags/cron/info

    希望这会有所帮助。如果没有,请在投票之前发表评论!

    Hope this helps. If it does not, post a comment before downvoting!

    这篇关于是否可以在Amazon Lightail实例上运行cron作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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