如何每天在Ubuntu操作系统上使用cron作业运行php脚本 [英] how to run a php script daily with the cron job on Ubuntu os
问题描述
运行命令我正在使用ubuntu 12和lamp服务器。我想每1小时运行一次php脚本。我创建了一个crontab来执行此操作,如果我使用命令crontab -l检查了我的cron列表,则显示为
command to runI am using ubuntu 12 and lamp server . I want to run a php script after every 1 hour . i have create a crontab to execute this and if i check my cron list with command crontab -l it is showing like this
# 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
但未执行
我如何检查为什么它不起作用,请帮助
how can i check why it is not working , please help
推荐答案
要确定cron出了什么问题,可以在终端中键入以下命令:
To find out what is wrong with your cron you can type the following command in your terminal:
grep -i "cron1.php" /var/log/syslog
系统日志包含所有cron日志。
The syslog contains all log of crons.
尝试运行代码 / usr / bin / php5 -q / var / www /终端上的cronjobs / cron1.php
来检查是否存在错误。
Try run the code /usr/bin/php5 -q /var/www/cronjobs/cron1.php
on terminal to check if there are errors.
您还可以重做将所有错误纠正为文件:
You can also redirect all errors to a file:
0 * * * * /usr/bin/php5 -q /var/www/cronjobs/cron1.php 2> /tmp/errorCron1.txt
这篇关于如何每天在Ubuntu操作系统上使用cron作业运行php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!