The usage of crontab Command to deal with scheduled tasks in Linux system
This article introduces the relevant knowledge of "the use of crontab commands to deal with scheduled tasks in the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Execute the operation command regularly, each user has its own crontab, and the configuration file is stored under / var and cannot be edited directly.
-e set timer
-l lists the settings for the current timer
-r delete timer settings
-I interactive mode, ask first when deleting timer settings
Column 1 column 2 3 4 5 6
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
There are many examples of crontab writing rules, the following from the Internet, lazy, heh heh
30 21 * / usr/local/etc/rc.d/lighttpd restart
The above example shows that lighttpd 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 lighttpd 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 lighttpd 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 lighttpd 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 lighttpd is restarted at 11: 00 pm every Saturday.
0 * / usr/local/etc/rc.d/lighttpd restart
Restart lighttpd every hour
* 23-7bat 1 * / usr/local/etc/rc.d/lighttpd restart
Restart lighttpd every other hour between 11:00 and 7 a.m.
0 11 4 * mon-wed / usr/local/etc/rc.d/lighttpd restart
Restart lighttpd 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 lighttpd at 4: 00 on January 1st
Special symbol
Symbolic meaning
* indicates that any time is fine
-indicates the range of values
For example:
00 17-19 * means 17 18 19 all perform tasks, indicating separation time.
For example
30, 17, 18, 19, 19 * means 17.30 18.30 19.30 execution / n n represents a number, indicating how often it is executed.
Example 1
The code is as follows:
[root@localhost ~] # crontab-l # View programs that run regularly
59 23 * / bin/sh / var/www/database/bak.sh
59 3 * / bin/sh / var/www/database/mylinux.sh
59 5 * 0 / sbin/reboot
The code is as follows:
[root@localhost ~] # crontab-e # add, edit
Example 2
Set the crontab to execute regularly every minute, and so on. Today, I posted it for everyone to use. Students who will be able to do so will float by.
Execute * / 5 * every five minutes
Execute 0 * per hour
Perform 0 0 * every day
Execute 0 0 * 0 every week
Execute 0 01 * * every month
0 0 1 1 * per year
This is the end of the content of "the use of crontab commands to deal with scheduled tasks in the Linux system". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!