要运行的命令我正在使用 ubuntu 12 和 lamp 服务器。我想每 1 小时运行一个 php 脚本。我已经创建了一个 crontab 来执行它,如果我用命令 crontab -l 检查我的 cron 列表,它会像这样显示
# Edit this file to introduce tasks to be run by cron.
0 * * * * /usr/bin/php5 -q /var/www/cronjobs/cron1.php
# 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
这是我的php脚本
0 * * * * /usr/bin/php5 -q /var/www/cronjobs/cron1.php
但它没有执行
我怎样才能检查它为什么不起作用,请帮忙
最佳答案
您可以使用 crontab 添加/删除/编辑 cronjobs。
按 Alt+Ctrl+T 打开终端。
首先通过运行确保脚本可执行:
chmod +x YOURSCRIPT
然后运行以下命令来添加您的 cronjob:
crontab -e
像这样添加你的 cronjob:
0 * * * * /usr/local/bin/php path/of/php/file
就是这样!
您可以通过运行以下命令来检查当前用户的 crontab 条目:
crontab -l
有关 crontab 运行的更多信息:
crontab --help
或
man crontab
关于php - 如何在 Ubuntu 操作系统上使用 cron 作业每天运行 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28235524/