Centos system crontab realizes automatic timing restart tutorial

For example: To set the method of restarting at 5 am every day:

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

crontab -e  
Press the Insert key to enter the edit mode

and then  in the document:

0 5 * * * /sbin/reboot
(note that The space in the middle, 0 5 means restart at 4 am every day and so on.. 0 6 means 6 am ..) 

After editing, press the esc key to exit the editing mode.

Type: wq to save and exit, and then

restart  crond service. The input content of

service crond restart
can be used to query the command just edited through the "crontab -l" command. For

reference

, cron is a timing execution tool under linux, which can be executed without manual intervention. Excuting an order.

The meaning of each parameter of the crontab command:

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

minute hour day month week command

Among them:

minute: Indicates the minute, which 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: Indicates the month, which can be any integer from 1 to 12.

week: Indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.

command: The command to be executed, which can be a system command or a script file written by yourself.


The method of setting automatic timing restart of linux centos server

In the above fields, you can also use the following special characters:

asterisk (*): represents all possible values, for example, if the month field is an asterisk, it means that it meets the constraints of other fields. The command action is executed every month after the condition.

Comma (,): A list range can be specified with comma-separated values, for example, "1,2,5,7,8,9"

Bars (-): A bar between integers can be used to indicate a range of integers , for example "2-6" means "2,3,4,5,6"

Forward slash (/): You can specify the interval frequency of time with a forward slash, for example "0-23/2" means to execute every two hours once. At the same time, forward slashes can be used together with asterisks, such as */10, if used in the minute field, it means to execute every ten minutes.

Detailed explanation of crontab command

1. Command format:

crontab [-u user] file

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

2.Command function:

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

3. Command parameters:

-u user: used to set the crontab service of a user, for example, "-u lao8" means to set the crontab service of the lao8 user, this parameter is generally run by the root user.

file: file is the name of the command file, indicating that file is used as the task list file of crontab and loaded into crontab. If this file is not specified on the command line, the crontab command will accept commands typed on standard input (keyboard) and load them into crontab.

-e: Edit the contents of a user's crontab file. If no user is specified, it means to edit the current user's crontab file.

-l: Display the content of a user's crontab file. If no user is specified, it means that the content of the current user's crontab file is displayed.

-r: Delete a user's crontab file from the /var/spool/cron directory. If no user is specified, the current user's crontab file will be deleted by default.

-i: Prompt for confirmation when deleting a user's crontab file.

Other examples of crond use

Example 1: Execute command

command every 1 minute:

* * * * * command



Example 2: Execute

command :

3,15 * * * * command



Example 3: At 8 in the morning Execute the

command from 11:00 am to:

3,15 8-11 * * * command



Example 4: Execute the

command :

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



instance 5: every Monday from 8 am to 11 am at the 3rd and 15th minute execution

command :

3,15 8-11 * * 1 command



instance 6: every Restart smb

command at 21:30 late :

30 21 * * * /etc/init.d/smb restart instance 7: restart smb command at 4:45



on 1, 10, 22 of every month : 45 4 1,10,22 * * /etc/init.d/smb restart instance 8: restart smb command every Saturday and Sunday at 1:10 : 10 1 * * 6,0 /etc/init.d/smb restart instance 9: every day at 18:00 Restart smb command every 30 minutes until 23:00 : 0,30 18-23 * * * /etc/init.d/smb restart instance 10: restart smb command every Saturday night at 11:00 pm : 0 23 * * 6 /etc/init.d/smb restart instance 11: restart the smb command every hour: * */1 * * * /etc/init.d/smb restart instance 12: between 11pm and 7am, Restart the smb command every hour :







































* 23-7/1 * * * /etc/init.d/smb restart Example 13: Restart the smb command

on the 4th of every month and at 11:00 every Monday to Wednesday : 0 11 4 * mon-wed /etc/init. d/smb restart Example 14: Restart the smb command at 4:00 on January 1st : 0 4 1 jan * /etc/init.d/smb restart Example 15: Execute the script in the /etc/cron.hourly directory every hour Command : 01 * * * * root run-parts /etc/cron.hourly The original text comes from: http://www.lao8.org/article_1760/linux_zidongchongqi.html The above is the content carefully prepared for you by the editor of Yunqi Community. There are also related content in the blog, Q&A, official account, characters, courses and other columns of the Qi community. You are welcome to continue to use the search button in the upper right corner to search for files, instances, parameters, formats, and time. User crontab scheduled restart, crontab scheduled task restart, crontab scheduled Restart services, restart centos crontab, restart crontab in centos 7, so that you can get more relevant knowledge.




















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326128104&siteId=291194637