如何在AWS EC2服务器中编写Cron作业 [英] How to write cron job in AWS EC2 server

查看:88
本文介绍了如何在AWS EC2服务器中编写Cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在AWS EC2中创建了一个cron作业,但是它不起作用。

I've created a cron job in AWS EC2 but it is not working.

我按照以下步骤创建了cron选项卡:

I followed below steps to create cron tab:


  • 步骤1:我登录到AWS EC2 Instace

  • 步骤2: crontab -e

  • 第3步:插入模式

  • 第4步:我输入了 * * * * * php / var / www / html / welcome.php (每分钟运行一次)

  • 第5步::wq

  • Step 1: I logged in to AWS EC2 Instace
  • step 2: crontab -e
  • Step 3: Insert mode
  • Step 4: I entered * * * * * php/var/www/html/welcome.php (To run every min.)
  • Step 5: :wq

Cron选项卡已创建但未运行。

Cron tab is created but not running.

请可以如果有任何PHP脚本意味着您可以帮助我,请提供给我。我需要在每颗星星之间留空格吗?

Please can you any one help me if is there any PHP script means please provide me. Do I need to give spaces between every star?

推荐答案

首先,您需要在<$ c $之间放置一个空格c> php 和 / var

来自

* * * * * php/var/www/html/welcome.php

* * * * * php /var/www/html/welcome.php
             ^

然后,最好使用 / bin / php 而不是 php 。要确定 php 可执行文件的位置,请在控制台中键入哪个php ,它将为您提供文件路径。因此它将变成这样:

Then, you'd better use /bin/php instead of just php. To determine where the php executable is located, type which php in your console, it will give you the file path. So it will become something like this:

* * * * * /bin/php /var/www/html/welcome.php
          ^^^^^^^^

更多东西:


  • 检查crontab是否正确保存?键入 crontab -l <​​/ code>。您的新crontab行应该在那里。

  • 脚本是否恰好在此目录中?尝试 ls -l /var/www/html/welcome.php

  • 如果从控制台执行,脚本是否正在执行?尝试 / bin / php var / www / html / welcome.php 看看这是脚本还是crontab问题。

  • 脚本有执行模式吗?尝试 chmod 755 /var/www/html/welcome.php

  • check if crontab is saved properly? Type crontab -l. Your new crontab line should be there.
  • is the script exactly in this dir? Try ls -l /var/www/html/welcome.php.
  • is the script executing if you do from console? Try /bin/php var/www/html/welcome.php to see if it is a script or crontab problem.
  • does the script have executing mode? Try chmod 755 /var/www/html/welcome.php

保持我们已更新,因此我们可以找到导致错误的原因。

Keep us updated so we can find what can be causing the error.

这篇关于如何在AWS EC2服务器中编写Cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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