简体   繁体   English

CRON无法在Amazon EC2中工作?

[英]CRON isn't working in Amazon EC2?

Another article describes that a way to test if cron is running is to create a crontab -e with this script: 另一篇文章介绍了一种测试cron是否正在运行的方法,即使用以下脚本创建crontab -e:

* * * * * /usr/bin/uptime > /tmp/uptime

When i go check on the cron cat /tmp/uptime there is no result. 当我去检查cron cat / tmp / uptime时,没有结果。 The same goes with a test script with a direct path to php. 带有直接指向php的测试脚本的情况也是如此。

I'm running AWS running Amazon Linux. 我正在运行运行Amazon Linux的AWS。

I checked to see if cron was even running with chkconfig --list crond result: 我检查了cron是否甚至与chkconfig --list crond结果一起运行:

crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

UPDATE (based on comments) 更新(基于注释)

[ec2-user@ip-xxx-xxx ~]$ service crond status
crond (pid  2844) is running...
[ec2-user@ip-xxx-xxx ~]$ ps aux | grep crond
root      2844  0.0  0.2 121636  2572 ?        Ss   Sep04   0:01 crond
ec2-user  7904  0.0  0.2 110468  2096 pts/0    S+   22:46   0:00 grep --color=auto crond

Just to be safe I manually started cron with this command: 为了安全起见,我使用以下命令手动启动了cron:

sudo service crond start

I've also tried sudo su and created instances both in ec2-user and root. 我还尝试了sudo su并在ec2-user和root中都创建了实例。 Nothing seems to actually run the cron. 似乎没有任何东西可以运行cron。

Does anyone have any suggestions? 有没有人有什么建议? It seems that the docs on Cron elsewhere are several years old. Cron上的其他文档似乎已有数年历史了。 Thanks in advance. 提前致谢。

Reference: 参考:

Setting Up Cron in Amazon Linux AMI 在Amazon Linux AMI中设置Cron

have you check the cron daemon status ? 您是否检查了cron守护程序状态?

$ service crond status
crond (pid xxx) is running...
$ ps aux | grep crond
root      2533  0.0  0.1 119552  1784 ?        Ss   Apr04   1:57 crond
ec2-user 22203  0.0  0.2 110460  2084 pts/0    S+   09:37   0:00 grep --color=auto crond

then, if cron daemon seems not running you can start it 然后,如果cron守护程序似乎未运行,则可以启动它

$ service crond start

Verify that procps package is installed (that package provides uptime command) 验证是否安装了procps软件包(该软件包提供了正常运行时间命令)

sudo yum install procps

Also verify that your cron job is saved 还要确认您的cron作业已保存

crontab -l

Do the following: 请执行下列操作:

sudo service crond reload 须藤服务crond重装

or 要么

sudo service crond restart sudo服务crond重新启动

This could happen to VPS server, after you do the crontab modification, you might need to reload it in order for the modification to take place. VPS服务器可能会发生这种情况,在进行crontab修改后,可能需要重新加载它才能进行修改。 In the worse case scenario, the crond restart will stop the service and start it again. 在最坏的情况下,crond重新启动将停止该服务,然后重新启动它。 Hope that helps. 希望能有所帮助。

     [ec2-user@ip-172-31-47-191 ~]$ sudo crontab -l
no crontab for root
[ec2-user@ip-172-31-47-191 ~]$ sudo crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[ec2-user@ip-172-31-47-191 ~]$ sudo crontab -l
* * * * * /usr/bin/uptime > /tmp/uptime

[ec2-user@ip-172-31-47-191 ~]$ /usr/bin/uptime
 23:05:09 up 284 days, 12:52,  1 user,  load average: 0.01, 0.02, 0.05
 [ec2-user@ip-172-31-47-191 ~]$ ls -l /tmp
total 4
drwx------. 2 oracle dba   6 Sep  7 11:03 mc-oracle
drwx------. 2 root   root  6 Sep  7 11:01 mc-root
-rw-r--r--. 1 root   root 71 Sep 14 23:05 uptime
 [ec2-user@ip-172-31-47-191 ~]$ more /tmp/uptime
 23:05:01 up 284 days, 12:52,  1 user,  load average: 0.01, 0.02, 0.05
 [ec2-user@ip-172-31-47-191 ~]$  service crond status
Redirecting to /bin/systemctl status  crond.service
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-04-20 03:07:03 EDT; 4 months 26 days ago
 Main PID: 16998 (crond)
   CGroup: /system.slice/crond.service
           └─16998 /usr/sbin/crond -n

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
[ec2-user@ip-172-31-47-191 ~]$ 191 ~]$

检查/ var / log / cron日志文件以验证您的命令是否正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM