Centos7: Uses crontab to regularly execute tasks. centos7crontab

Source: Internet
Author: User

Centos7: Uses crontab to regularly execute tasks. centos7crontab

The cron service is a built-in service in Linux, but it does not start automatically when it is started. Run the following command to start and stop the service:

/sbin/service crond start
/sbin/service crond stop
/sbin/service crond restart
/sbin/service crond reload

The preceding lines start, stop, restart the service, and reload the configuration.

Set the cron to automatically start when it is started, and add it to the/etc/rc. d/rc. local script./sbin/service crond startYou can.

View the current user's crontab and enter crontab-l;

Edit crontab and enter crontab-e;

Delete crontab and enter crontab-r.

 

Add task

  crontab -e  0 */1 * * * command  0 */2 * * * command

Check whether the task has been added:

Crontab-l-u root # view the root user 0 */1 *** command 0 */2 *** command
Basic Format:
* *** Command
Minute, day, month, week, command column 1st indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
Example of the crontab file to be run in column 6th: 30 21 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates restarting apache at every night. 45 4, 10, 22 **/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at on the 1st, 10th, and 22th every month. 10 1 ** 6, 0/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday and Sunday. 0, 30 18-23 ***/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted every 30 minutes between and every day. 0 23 ** 6/usr/local/etc/rc. d/lighttpd restart
The preceding example indicates that apache is restarted at every Saturday. **/1 ***/usr/local/etc/rc. d/lighttpd restart
Restart apache ** 23-7/1 ***/usr/local/etc/rc. d/lighttpd restart every hour
Restart apache0 11 4 * mon-wed/usr/local/etc/rc. d/lighttpd restart from PM to PM.
Restart apache0 4 1 jan */usr/local/etc/rc. d/lighttpd restart at every Monday to Wednesday.
Restart apache at on January 1, January 1

Related Article

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.