Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use crontab to perform tasks regularly in Centos 7

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

How do I use crontab to perform tasks regularly in Centos 7? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

The cron service is a built-in service for Linux, but it does not boot up automatically. You can start and stop the service with the following command:

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

The above 1-4 lines are starting, stopping, restarting the service, and reloading the configuration.

To set cron to start automatically at boot time, add / sbin/service crond start to the / etc/rc.d/rc.local script

To view the crontab of the current user, enter crontab-l

Edit crontab, enter crontab-e

Delete crontab and enter crontab-r

Add Task

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

Query whether the task has been added:

Crontab-l-u root # View root user 0 * / 1 * command 0 * / 2 * command

Basic format:

* command

Time-sharing, day, month and week order

Column 1 represents minutes 1: 59 per minute is represented by * or * / 1.

The second column represents the hour 1: 23 (0 means 0 o'clock)

The third column represents the date 1: 31

The fourth column represents the month from January to December.

The fifth column identification number is 0006 (0 means Sunday)

Column 6 commands to run

Some examples of crontab files:

30 21 * / usr/local/etc/rc.d/lighttpd restart

The above example shows that apache is restarted at 21:30 every night.

45-4-1-10-10-22 * / usr/local/etc/rc.d/lighttpd restart

The above example shows that apache is restarted at 4: 45 on the 1st, 10th, and 22nd of each month.

10 1 * * 6 0 / usr/local/etc/rc.d/lighttpd restart

The above example shows that apache is restarted at 1: 10 every Saturday and Sunday.

0pr 30 18-23 * / usr/local/etc/rc.d/lighttpd restart

The above example shows that apache is restarted every 30 minutes between 18: 00 and 23: 00 every day.

0 23 * * 6 / usr/local/etc/rc.d/lighttpd restart

The above example shows that apache is restarted at 11: 00 pm every Saturday.

* * / 1 * / usr/local/etc/rc.d/lighttpd restart

Restart apache every hour

* 23-7bat 1 * / usr/local/etc/rc.d/lighttpd restart

Restart apache every other hour between 11:00 and 7 a.m.

0 11 4 * mon-wed / usr/local/etc/rc.d/lighttpd restart

Restart apache on the 4th of each month and 11:00 from Monday to Wednesday

0 4 1 jan * / usr/local/etc/rc.d/lighttpd restart

Restart apache at 4: 00 on January 1st

This is the answer to the question about how to use crontab to perform tasks regularly in Centos 7. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report