How to enable automatic and scheduled restart of crontab in centos

Source: Internet
Author: User
Tags time interval centos centos server


For example, set the restart method at every day:

After successfully logging on to the server using the SSH tool, run the following command:

Crontab-e
Press the Insert key to enter the editing mode.

Then, enter:

0 5 ***/sbin/reboot
(Pay attention to spaces in the middle. 0 5 indicates restarting at every morning, and so on. 0 6 indicates A.M ..)

After editing, press esc to exit the editing mode.

Type: wq save and exit

Restart the crond service.

Service crond restart
You can run the "crontab-l" command to query the edited command.

Reference

Cron is a linux scheduled execution tool that can execute commands without manual intervention.

Meanings of parameters of the crontab command:

In the crontab file created by the user, each row represents a task, and each field in each row represents a setting. Its format is divided into six Fields. The first five fields are time sets, the sixth part is the command segment to be executed. The format is as follows:

Minute hour day month week command

Where:

Minute: minute. It can be any integer from 0 to 59.

Hour: indicates the hour, which can be any integer from 0 to 23.

Day: indicates the date, which can be any integer from 1 to 31.

Month: represents the month, which can be any integer from 1 to 12.

Week: The day of the week. It can be any integer from 0 to 7. Here 0 or 7 represents Sunday.

Command: The command to be executed. It can be a system command or a script file compiled by yourself.

 
How to set automatic and timed restart for linux centos server
 
You can also use the following special characters in the preceding fields:

Asterisk (*): represents all possible values. For example, if the month field is an asterisk, this command is executed every month after the conditions of other fields are met.

Comma (,): values separated by commas (,) can be used to specify a list range, for example"

Middle bars (-): You can use the middle bars between integers to represent an integer range. For example, "2-6" indicates "2, 3, 4, 5, 6"

Forward slash (/): You can use a forward slash to specify the interval of time. For example, "0-23/2" indicates that execution is performed every two hours. At the same time, the forward slash can be used with the star number, for example, */10. If it is used in the minute field, it indicates that the execution is performed every ten minutes.

Crontab command details

1. Command format:

Crontab [-u user] file

Crontab [-u user] [-e |-l |-r]

2. Command functions:

Through the crontab command, we can execute the specified system command or shell script at a fixed interval. The time interval can be any combination of minutes, hours, days, months, weeks, and above. This command includes non-permanent and periodic log analysis or data backup.

3. Command parameters:

-U user: used to set the crontab service for a user. For example, "-u lao8" indicates to set the crontab service for the lao8 user. This parameter is generally run by the root user.

File: file is the name of the command file. It indicates that file is used as the task list file of crontab and is loaded into crontab. If this file is not specified in the command line, the crontab command accepts the commands typed on the standard input (keyboard) and loads them into the crontab.

-E: edit the contents of a user's crontab file. If no user is specified, the crontab file of the current user is edited.

-L: displays the contents of a user's crontab file. If no user is specified, the contents of the current user's crontab file are displayed.

-R: deletes the crontab file of a user from the/var/spool/cron Directory. If no user is specified, the crontab file of the current user is deleted by default.

-I: A confirmation prompt is displayed when the user's crontab file is deleted.

Other crond instances

Instance 1: Execute command once every minute

Command:

* *** Command

 

Instance 2: 3rd and 15th minutes per hour

Command:

3, 15 * command

 

Instance 3: Run at 3rd and 15th minutes from eight o'clock A.M.

Command:

3, 15 8-11 *** command

 

Instance 4: runs every two days, from eight o'clock A.M. to, at 3rd and 15th minutes.

Command:

3, 15 8-11 */2 ** command

 

Instance 5: run the task at 3rd and 15th minutes from eight o'clock A.M. to every Monday.

Command:

3, 15 8-11 ** 1 command

 

Instance 6: restart smb at every night

Command:

30 21 ***/etc/init. d/smb restart

 

Instance 7: restart smb at on the 1st, 10th, and 22th of every month

Command:

45 4, 10, 22 **/etc/init. d/smb restart

 

Instance 8: restart smb every Saturday or Sunday

Command:

10 1 ** 6, 0/etc/init. d/smb restart

 

Instance 9: restart smb every 30 minutes between and every day

Command:

0, 30 18-23 ***/etc/init. d/smb restart

 

Instance 10: restart smb at every Saturday.

Command:

0 23 ** 6/etc/init. d/smb restart

Instance 11: restart smb every hour

Command:

**/1 ***/etc/init. d/smb restart

Instance 12: restart smb every hour between PM and PM.

Command:

* 23-7/1 ***/etc/init. d/smb restart

Instance 13: restart smb at from Monday to Wednesday on the 4th of each month

Command:

0 11 4 * mon-wed/etc/init. d/smb restart

 
Instance 14: restart smb at on January 1, January 1

Command:

0 4 1 jan */etc/init. d/smb restart

Example 15: execute scripts in the/etc/cron. hourly directory every hour.

Command:

01 *** root run-parts/etc/cron. hourly

From: http://www.lao8.org/article_1760/linux_zidongchongqi.html

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.