yingfeng
The heart is as bright as a mirror. If you don't, you won't be welcomed

Use of Cron Scheduled Tasks

Cron is a scheduled execution tool under Linux, which can run jobs without human intervention. It is a built-in service of Linux, so we will use it in many cases.

First of all, how to enable/disable the service

 //Start Service sudo service cron start //Stop service sudo service cron stop //Restart service sudo service cron restart //Reload configuration sudo service cron reload

Most of the VPS planning tasks have been added to the startup and auto start by default, but some VPS (such as tile removal workers) have not added them to the startup and auto start. If we want to use Cron, we must make it start automatically, otherwise it would be ridiculous to have to manually pull it up every time.

It is also simple to add it to the boot auto start method. Add/sbin/service crond start or sudo service cron start directly to/etc/rc.d/rc.local

Then edit the scheduled task

Use the crontab - e command to edit the configuration of the scheduled task

Cron configuration file format:

"*" represents the number within the value range

"/" represents "every"

"-" means from a certain number to a certain number

Separate several discrete numbers

Here are some examples:

 * 03 * * * sys/bin/reboot //Restart at 3:00 every morning */1 * * * * /usr/local/php/bin/php /home/www/test/do.php //Execute once every 1 minute * * * do.php */1 8-12 * * * /usr/local/php/bin/php /home/www/test/do.php //Execute every minute from 8:00 to 12:00 every day * * * do.php 30 9,12,17 * * * /usr/local/php/bin/php /home/www/test/do.php //Execute once every day at 9:30,12:30,17:30 * * * do.php

After modifying the file, wq saves and exits. Then use sudo service cron reload to reload the configuration of the scheduled task

This article is published at: yingfeng Blog >> Use of Cron Scheduled Tasks , please indicate the source for reprinting.

comment four

  • Nickname (required)
  • Email (required)
  • website
  1. #0

    The main reason is that this format is easy to use and easy to integrate with Quartz

    VPS234 Five years ago (2019-09-03) reply
  2. #0

    Don't you need to add a - f to execute php script/ usr/local/php/bin/php -f /home/www/test/do.php

    Flute sound Six years ago (2018-02-19) reply
    • I didn't add - f, it's good. 0.0

      yingfeng Six years ago (2018-02-20) reply
  3. #0

    Crontab is really easy to use~~Linux is a must~

    Long Xiaotian Six years ago (2018-02-10) reply