在AWS ec2中执行Cron任务,但它不工作

2022-01-30 13:47:07 标签 phpamazon-ec2cron

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

我按照下面的步骤创建crontab:

Step 1: I logged in to AWS EC2 Instance.
step 2: crontab -e
Step 3: Insert mode
Step 4: I entered */5 * * * * php /var/www/html/task1.php
Step 5: :wq

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

我都试过什么?

1. */5 * * * * php /var/www/html/task1.php
2. */5 * * * * /bin/php /var/www/html/task1.php
3. */5 * * * * /usr/bin/php /var/www/html/task1.php > /dev/null 2>&1 

但没有运气使用以上,也在保存这些后,我已经重启服务器,以及->Sudo systemctl restart apache2

我检查了日志并发现了下面的消息(最后100行task1。php只是一个示例名称,但原始名称是translate-audi。php,感谢理解)。

Sep 19 09:45:01 ip-172-31-30-156 CRON[52479]: (ubuntu) CMD (/usr/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 09:49:41 ip-172-31-30-156 crontab[52493]: (ubuntu) LIST (ubuntu)
Sep 19 09:50:01 ip-172-31-30-156 CRON[52519]: (ubuntu) CMD (/usr/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 09:53:05 ip-172-31-30-156 crontab[52580]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 09:53:13 ip-172-31-30-156 crontab[52580]: (ubuntu) END EDIT (ubuntu)
Sep 19 09:53:57 ip-172-31-30-156 crontab[52589]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 09:55:01 ip-172-31-30-156 CRON[52598]: (ubuntu) CMD (/usr/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 09:55:19 ip-172-31-30-156 crontab[52589]: (ubuntu) REPLACE (ubuntu)
Sep 19 09:55:19 ip-172-31-30-156 crontab[52589]: (ubuntu) END EDIT (ubuntu)
Sep 19 09:55:32 ip-172-31-30-156 systemd[1]: Stopping The Apache HTTP Server...
Sep 19 09:55:33 ip-172-31-30-156 systemd[1]: apache2.service: Succeeded.
Sep 19 09:55:33 ip-172-31-30-156 systemd[1]: Stopped The Apache HTTP Server.
Sep 19 09:55:33 ip-172-31-30-156 systemd[1]: Starting The Apache HTTP Server...
Sep 19 09:55:33 ip-172-31-30-156 systemd[1]: Started The Apache HTTP Server.
Sep 19 09:55:51 ip-172-31-30-156 crontab[52634]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 09:56:01 ip-172-31-30-156 cron[450]: (ubuntu) RELOAD (crontabs/ubuntu)
Sep 19 09:56:33 ip-172-31-30-156 crontab[52634]: (ubuntu) REPLACE (ubuntu)
Sep 19 09:56:33 ip-172-31-30-156 crontab[52634]: (ubuntu) END EDIT (ubuntu)
Sep 19 09:56:38 ip-172-31-30-156 crontab[52640]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 09:56:44 ip-172-31-30-156 crontab[52640]: (ubuntu) END EDIT (ubuntu)
Sep 19 09:56:49 ip-172-31-30-156 crontab[52645]: (ubuntSep 19 09:56:49 ip-172-31-30-156 crontab[52645]: (ubuntu) LIST (ubuntu)
Sep 19 09:57:01 ip-172-31-30-156 cron[450]: (ubuntu) RELOAD (crontabs/ubuntu)
Sep 19 09:57:37 ip-172-31-30-156 systemd[1]: Stopping The Apache HTTP Server...
Sep 19 09:57:37 ip-172-31-30-156 systemd[1]: apache2.service: Succeeded.
Sep 19 09:57:37 ip-172-31-30-156 systemd[1]: Stopped The Apache HTTP Server.
Sep 19 09:57:37 ip-172-31-30-156 systemd[1]: Starting The Apache HTTP Server...
Sep 19 09:57:37 ip-172-31-30-156 systemd[1]: Started The Apache HTTP Server.
Sep 19 10:00:01 ip-172-31-30-156 CRON[52686]: (ubuntu) CMD (/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 10:05:01 ip-172-31-30-156 CRON[52774]: (ubuntu) CMD (/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 10:09:01 ip-172-31-30-156 CRON[52811]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Sep 19 10:09:32 ip-172-31-30-156 systemd[1]: Starting Clean php session files...
Sep 19 10:09:32 ip-172-31-30-156 systemd[1]: phpsessionclean.service: Succeeded.
Sep 19 10:09:32 ip-172-31-30-156 systemd[1]: Finished Clean php session files.
Sep 19 10:10:01 ip-172-31-30-156 CRON[52879]: (ubuntu) CMD (/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 10:15:01 ip-172-31-30-156 CRON[52907]: (ubuntu) CMD (/bin/php /var/www/html/autotranslate-dev-ec2/translate-audi.php > /dev/null 2>&1)
Sep 19 10:17:01 ip-172-31-30-156 CRON[52928]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Sep 19 10:18:08 ip-172-31-30-156 crontab[52941]: (ubuntu) LIST (ubuntu)
Sep 19 10:18:21 ip-172-31-30-156 crontab[52942]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 10:18:52 ip-172-31-30-156 crontab[52942]: (ubuntu) REPLACE (ubuntu)
Sep 19 10:18:52 ip-172-31-30-156 crontab[52942]: (ubuntu) END EDIT (ubuntu)
Sep 19 10:19:01 ip-172-31-30-156 cron[450]: (ubuntu) RELOAD (crontabs/ubuntu)
Sep 19 10:19:44 ip-172-31-30-156 crontab[52954]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 10:20:00 ip-172-31-30-156 crontab[52954]: (ubuntu) END EDIT (ubuntu)
Sep 19 10:20:01 ip-172-31-30-156 CRON[52963]: (ubuntu) CMD (/bin/php /var/www/html/translate-audi.php > /dev/null 2>&1)
Sep 19 10:20:42 ip-172-31-30-156 systemd[1]: Stopping The Apache HTTP Server...
Sep 19 10:20:43 ip-172-31-30-156 systemd[1]: apache2.service: Succeeded.
Sep 19 10:20:43 ip-172-31-30-156 systemd[1]: Stopped The Apache HTTP Server.
Sep 19 10:20:43 ip-172-31-30-156 systemd[1]: Starting The Apache HTTP Server...
Sep 19 10:20:43 ip-172-31-30-156 systemd[1]: Started The Apache HTTP Server.
Sep 19 10:25:01 ip-172-31-30-156 CRON[53006]: (ubuntu) CMD (/bin/php /var/www/html/translate-audi.php > /dev/null 2>&1)
Sep 19 10:27:59 ip-172-31-30-156 crontab[53011]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 10:30:01 ip-172-31-30-156 CRON[53023]: (ubuntu) CMD (/bin/php /var/www/html/translate-audi.php > /dev/null 2>&1)
Sep 19 10:30:34 ip-172-31-30-156 crontab[53011]: (ubuntu) END EDIT (ubuntu)
Sep 19 10:30:36 ip-172-31-30-156 crontab[53026]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 10:31:01 ip-172-31-30-156 crontab[53026]: (ubuntu) REPLACE (ubuntu)
Sep 19 10:31:01 ip-172-31-30-156 crontab[53026]: (ubuntu) END EDIT (ubuntu)
Sep 19 10:31:01 ip-172-31-30-156 cron[450]: (ubuntu) RELOAD (crontabs/ubuntu)
Sep 19 10:31:06 ip-172-31-30-156 crontab[53032]: (ubuntu) BEGIN EDIT (ubuntu)
Sep 19 10:31:11 ip-172-31-30-156 crontab[53032]: (ubuntu) END EDIT (ubuntu)
Sep 19 10:31:17 ip-172-31-30-156 systemd[1]: Stopping The Apache HTTP Server...
Sep 19 10:31:17 ip-172-31-30-156 systemd[1]: apache2.service: Succeeded.
Sep 19 10:31:17 ip-172-31-30-156 systemd[1]: Stopped The Apache HTTP Server.
Sep 19 10:31:17 ip-172-31-30-156 systemd[1]: Starting The Apache HTTP Server...
Sep 19 10:31:17 ip-172-31-30-156 systemd[1]: Started The Apache HTTP Server.
Sep 19 10:35:01 ip-172-31-30-156 CRON[53072]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 10:35:01 ip-172-31-30-156 CRON[53069]: (CRON) info (No MTA installed, discarding output)
Sep 19 10:39:01 ip-172-31-30-156 CRON[53086]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi)
Sep 19 10:39:21 ip-172-31-30-156 systemd[1]: Starting Clean php session files...
Sep 19 10:39:21 ip-172-31-30-156 systemd[1]: phpsessionclean.service: Succeeded.
Sep 19 10:39:21 ip-172-31-30-156 systemd[1]: Finished Clean php session files.
Sep 19 10:40:01 ip-172-31-30-156 CRON[53152]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 10:40:01 ip-172-31-30-156 CRON[53150]: (CRON) info (No MTA installed, discarding output)
Sep 19 10:45:01 ip-172-31-30-156 CRON[53161]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 10:45:01 ip-172-31-30-156 CRON[53159]: (CRON) info (No MTA installed, discarding output)
Sep 19 10:45:08 ip-172-31-30-156 systemd[1]: Started Session 37 of user ubuntu.
Sep 19 10:46:10 ip-172-31-30-156 crontab[53282]: (ubuntu) LIST (ubuntu)
Sep 19 10:50:01 ip-172-31-30-156 CRON[53293]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 10:50:01 ip-172-31-30-156 CRON[53290]: (CRON) info (No MTA installed, discarding output)
Sep 19 10:55:01 ip-172-31-30-156 CRON[53309]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 10:55:01 ip-172-31-30-156 CRON[53308]: (CRON) info (No MTA installed, discarding output)
Sep 19 11:00:01 ip-172-31-30-156 CRON[53320]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 11:00:01 ip-172-31-30-156 CRON[53318]: (CRON) info (No MTA installed, discarding output)
Sep 19 11:05:01 ip-172-31-30-156 CRON[53338]: (ubuntu) CMD (php /var/www/html/translate-audi.php)
Sep 19 11:05:01 ip-172-31-30-156 CRON[53337]: (CRON) info (No MTA installed, discarding output)

如果我遗漏了什么,有人能帮我吗?

提前谢谢。

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码