试图在ubuntu服务器上创建cron

试图在ubuntu服务器上创建cron,ubuntu,Ubuntu,我一直在尝试创建一个似乎不起作用的cron。我正在运行Ubuntu 14.04。为了进行测试,我将cron设置为每分钟运行一次 顺便说一句,我使用“sudo crontab-e”创建了cron。不确定是否需要sudo,但考虑了为什么不需要,以防权限可能是个问题(顺便说一句,没有sudo,php脚本可以从命令行正常运行) 这是我尝试过的几个变体,但不起作用 1 * * * * /usr/local/bin/php /var/www/html/test/index.php 1 * *

我一直在尝试创建一个似乎不起作用的cron。我正在运行Ubuntu 14.04。为了进行测试,我将cron设置为每分钟运行一次

顺便说一句,我使用“sudo crontab-e”创建了cron。不确定是否需要sudo,但考虑了为什么不需要,以防权限可能是个问题(顺便说一句,没有sudo,php脚本可以从命令行正常运行)

这是我尝试过的几个变体,但不起作用

    1 * * * * /usr/local/bin/php /var/www/html/test/index.php
    1 * * * * /var/www/html/test/index.php
还有,这是我的克朗(整件事)


如果尚未启动cron服务,请尝试使用以下命令启动cron服务
/etc/init.d/crond start
。希望这有帮助,如果没有,请告诉我们。

刚刚开始工作。这是正确的代码

          • php/var/www/html/test/index.php

在读了这篇文章后,我终于明白了

如果作业可以在您的正常帐户下运行,则cron作业不需要
sudo
。当你不知道的时候,“为什么不”不是使用
sudo
的好理由。但奇怪的是:为什么你想把PHP网页作为cron作业来运行?如果它不是一个网页,我不会把它放在
/var/www/
中。我想用sudo测试它,看看是否有权限妨碍了它。我想作为cron运行一个php脚本,因为它是我所知道的脚本语言(我所知道的所有hokery扑克都是用php编写的)。。。但我很快就会学习python。。。我现在觉得有必要!在键入命令时尝试了该命令,下面是错误消息,-bash:/etc/init.d/crond:没有这样的文件或目录使用sudo权限尝试该命令。获取此错误消息。。。sudo:/etc/init.d/crond:未找到命令刚刚尝试。。。sudo/etc/init.d/cron reload…没有收到任何错误消息,但在“sudo restart cron”或“sudo start cron”一分钟后没有发生任何事情。您还可以添加一个简单的作业,如“***/usr/bin/touch/tmp/cron”,并每分钟检查/tmp/cron是否有新的时间戳。
    # Edit this file to introduce tasks to be run by cron.
    # 
    # Each task to run has to be defined through a single line
    # indicating with different fields when the task will be run
    # and what command to run for the task
    # 
    # To define the time you can provide concrete values for
    # minute (m), hour (h), day of month (dom), month (mon),
    # and day of week (dow) or use '*' in these fields (for 'any').# 
    # Notice that tasks will be started based on the cron's system
    # daemon's notion of time and timezones.
    # 
    # Output of the crontab jobs (including errors) is sent through
    # email to the user the crontab file belongs to (unless redirected).
    # 
    # For example, you can run a backup of all your user accounts
    # at 5 a.m every week with:
    # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
    # 
    # For more information see the manual pages of crontab(5) and cron(8)
    # 

    # m h  dom mon dow   command
    1 * * * * /var/www/html/test/index.php
    ~             
    ~