I've created a cron job in AWS EC2 but it is not working.
我在AWS EC2中创建了一个cron作业,但它无法正常工作。
I followed below steps to create cron tab:
我按照以下步骤创建了cron选项卡:
- Step 1: I logged in to AWS EC2 Instace
- 第1步:我登录AWS EC2 Instace
- step 2:
crontab -e
- 第2步:crontab -e
- Step 3: Insert mode
- 第3步:插入模式
- Step 4: I entered
* * * * * php/var/www/html/welcome.php
(To run every min.) - 第4步:我输入* * * * * php / var / www / html / welcome.php(每分钟运行一次)
- Step 5:
:wq
- 第五步:wq
Cron tab is created but not running.
Cron选项卡已创建但未运行。
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?
如果有任何PHP脚本意味着请提供给我,请帮助我。我是否需要在每颗恒星之间留出空间?
3 个解决方案
#1
43
First of all, you need to put an space between php
and /var
:
首先,你需要在php和/ var之间放一个空格:
From
从
* * * * * php/var/www/html/welcome.php
to
至
* * * * * php /var/www/html/welcome.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而不仅仅是php。要确定php可执行文件的位置,在控制台中键入哪个php,它将为您提供文件路径。所以它会变成这样的:
* * * * * /bin/php /var/www/html/welcome.php
^^^^^^^^
More things:
更多的东西:
- check if crontab is saved properly? Type
crontab -l
. Your new crontab line should be there. - 检查crontab是否正确保存?输入crontab -l。你的新crontab行应该在那里。
- is the script exactly in this dir? Try
ls -l /var/www/html/welcome.php
. - 是这个目录中的脚本吗?试试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. - 如果你从控制台执行脚本是执行?尝试/ bin / php var / www / html / welcome.php查看它是否是脚本或crontab问题。
- does the script have executing mode? Try
chmod 755 /var/www/html/welcome.php
- 脚本有执行模式吗?试试chmod 755 /var/www/html/welcome.php
Keep us updated so we can find what can be causing the error.
让我们更新,以便我们可以找到可能导致错误的原因。
#2
3
Running cron on EC2 is not any different from running on any *nix server - as far as I know. I would check of the system messages for any errors. You can also redirect stderr/stdout to a file as in
在EC2上运行cron与在任何* nix服务器上运行没有任何不同 - 据我所知。我会检查系统消息是否有任何错误。您还可以将stderr / stdout重定向到文件中
* * * * * <your script> >> /var/tmp/out.log 2>&1
and check for any issues for starters.
并检查初学者的任何问题。
#3
3
May be a too late but anyways if you intend to run the script every minute the command should probably be
可能为时已晚,但如果您打算每隔一分钟运行该命令,那么该命令可能应该是
* * * * * php /var/www/html/welcome.php
#1
43
First of all, you need to put an space between php
and /var
:
首先,你需要在php和/ var之间放一个空格:
From
从
* * * * * php/var/www/html/welcome.php
to
至
* * * * * php /var/www/html/welcome.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而不仅仅是php。要确定php可执行文件的位置,在控制台中键入哪个php,它将为您提供文件路径。所以它会变成这样的:
* * * * * /bin/php /var/www/html/welcome.php
^^^^^^^^
More things:
更多的东西:
- check if crontab is saved properly? Type
crontab -l
. Your new crontab line should be there. - 检查crontab是否正确保存?输入crontab -l。你的新crontab行应该在那里。
- is the script exactly in this dir? Try
ls -l /var/www/html/welcome.php
. - 是这个目录中的脚本吗?试试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. - 如果你从控制台执行脚本是执行?尝试/ bin / php var / www / html / welcome.php查看它是否是脚本或crontab问题。
- does the script have executing mode? Try
chmod 755 /var/www/html/welcome.php
- 脚本有执行模式吗?试试chmod 755 /var/www/html/welcome.php
Keep us updated so we can find what can be causing the error.
让我们更新,以便我们可以找到可能导致错误的原因。
#2
3
Running cron on EC2 is not any different from running on any *nix server - as far as I know. I would check of the system messages for any errors. You can also redirect stderr/stdout to a file as in
在EC2上运行cron与在任何* nix服务器上运行没有任何不同 - 据我所知。我会检查系统消息是否有任何错误。您还可以将stderr / stdout重定向到文件中
* * * * * <your script> >> /var/tmp/out.log 2>&1
and check for any issues for starters.
并检查初学者的任何问题。
#3
3
May be a too late but anyways if you intend to run the script every minute the command should probably be
可能为时已晚,但如果您打算每隔一分钟运行该命令,那么该命令可能应该是
* * * * * php /var/www/html/welcome.php