即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

使用crontab来执行脚本的每一分钟,每24小时[关闭]

栈溢出 Teun Zengerink 5℃ 0评论
本文目录
[隐藏]

1.原始问题:Using crontab to execute script every minute and another every 24 hours [closed]

I need a crontab syntax which should execute a specific PHP script /var/www/html/a.php every minute. The execution on every minute must start at 00:00. The other task which must execute a script at 00:00 /var/www/html/reset.php (once every 24 hours).

2.被采纳答案

every minute:

* * * * * /path/to/php /var/www/html/a.php

every 24hours (every midnight):

0 0 * * * /path/to/php /var/www/html/reset.php

See this reference for how crontab works: http://adminschoice.com/crontab-quick-reference, and this handy tool to build cron jobx: http://www.htmlbasix.com/crontab.shtml

3.其他高票答案

3.1.第1个答案

This is the format of /etc/crontab:

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

I recommend copy & pasting that into the top of your crontab file so that you always have the reference handy. RedHat systems are setup that way by default.

To run something every minute:

* * * * * username /var/www/html/a.php

To run something at midnight of every day:

0 0 * * * username /var/www/html/reset.php

You can either include /usr/bin/php in the command to run, or you can make the php scripts directly executable:

chmod +x file.php

Start your php file with a shebang so that your shell knows which interpreter to use:

#!/usr/bin/php

转载请注明:CodingBlog » 使用crontab来执行脚本的每一分钟,每24小时[关闭]

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情