Linux crontab Commands

Source: Internet
Author: User
Install Crontab:

Yum Install Crontabs

Basic cron Service Control commands:

Code

    1. /sbin/service crond Start //Start service
    2. /sbin/service Crond Stop //Shut down service
    3. /sbin/service crond Restart //Restart service
    4. /sbin/service Crond Reload //Reload configuration

View crontab Service Status: Crond status

Manually Start crontab services: Service Crond start

To see if the Crontab service is set to boot, execute command: NTSYSV

Join power on Auto start: Chkconfig--level Crond on

If you want to learn more about the Chkconfig--level command, http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html explain it in more detail.

Crontab Command Introduction

Code

    1. Feature Description: Set the timer.
    2. Syntax: crontab [-u <用户名称> ] [configuration file] or crontab [-u <用户名称> ][-ELR]
    3. Additional note: Cron is a resident service that provides the function of a timer that allows the user to execute a preset instruction or program at a specific time. The function of the timer can be used as long as the user edits the timer's configuration file. Its configuration file format is as follows:
    4. Minute Hour Day Month DayOFWeek Command
    5. Parameters
    6. -e Edit the user's timer settings.
    7. -l lists the user's timer settings.
    8. -R removes the user's timer settings.
    9. <用户名称> -u Specifies the name of the user to set the timer.

crontab format

Code

  1. Basic format:
  2. * * * * * command
  3. Time-sharing Weekly command
  4. The 1th column represents minutes 1~59 per minute with * or */1
  5. The 2nd column represents the hour 1~23 (0 means 0 points)
  6. The 3rd column represents the date 1~31
  7. The 4th column represents the month 1~12
  8. 5th Column Identification Number Week 0~6 (0 = Sunday)
  9. 6th List of commands to run
  10. # Use the hash sign to prefix a comment
  11. # + —————-minute (0–59)
  12. # | + ————-Hour (0–23)
  13. # | | + ———-Day of month (1–31)
  14. # | | | + ——-Month (1–12)
  15. # | | | | +--Day of Week (0–7) (sunday=0 or 7)
  16. # | | | | |
  17. # * * * * * command to be executed

Some examples of crontab files:

Code

  1. - * * * * /etc/init.d/nginx Restart
  2. Every night : re-start Nginx.
  3. $ 4 1,ten, * */etc/ Init.d/nginx Restart
  4. 4 : 45 per month, 1,ten, Day Restart nginx.
  5. Ten 1 * * 6,0 /etc/init.d/nginx restart
  6. Every Saturday, Sunday of 1 : restart nginx.
  7. 0 , - * * * * * /etc/init.d/nginx Restart
  8. Per Day : from xx to : every Restart nginx in five minutes.
  9. 0 * * 6 /etc/init.d/nginx Restart
  10. Every Saturday : pm to restart Nginx.
  11. * * * *1 * * */etc/init.d/nginx restart
  12. Restart Nginx every hour
  13. * 7/1 * * */etc/init.d/nginx restart
  14. In the evening , between 7 o ' Day, restart Nginx every hour .
  15. 0 4 * mon-wed/etc/init.d/nginx restart
  16. 4 monthly and every Monday to Wednesday, restart nginx .
  17. 0 4 1 Jan */etc/init.d/nginx Restart
  18. 4- Point Restart of nginx on January 1
  19. * * * * * * * * /usr/sbin/ntpdate 210.72. 145.20
  20. Synchronize time every half hour

Apply to Thinkphp

First you have to write the function code that you want to execute on a regular basis into the action. Or you can do it after you access it with a URL.

For example, I put the update code for the regular daily traversal of the order to see if the turnover is order/update_status.

My Project Access address is www.jieqinwang.com that is: The code execution path for this feature is: Http://www.jieqinwang.com/Order/update_status

After you get this path, you can go to Liunx to configure Cron.

Crontab-e into the task list.

Press the I key to enter edit mode, and then add a task.

For example, I want to execute the code I just wrote every day 12 o'clock noon.

Just add a new line 0 * * * * Curl Http://www.jieqinwang.com/Order/update_status

Then press the ESC key to exit edit mode and enter: Wq enter. Save exit.

This allows us to add a timed task. You can use Crontab-l to see if the task list is already contained.

The last step, as such additions may not take effect immediately. We can restart the cron service.

Restart Service command: / sbin / service crond restart

Original link: http://164418960.iteye.com/blog/2170536


The above describes the Linux crontab command, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.