In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use crontab". In daily operation, I believe many people have doubts about how to use crontab. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use crontab". Next, please follow the editor to study!
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
Name: crontab
Permissions: all users
Mode of use:
Crontab file [- u user]-replaces the current crontab with the specified file.
Crontab- [- u user]-replace the current crontab with standard input.
Crontab-1 [user]-lists the user's current crontab.
Crontab-e [user]-Editing the user's current crontab.
Crontab-d [user]-deletes the user's current crontab.
Crontab-c dir- specifies the directory of the crontab.
Crontab file format: M H D md cmd.
M: minutes (0-59).
H: hours (0-23).
D: days (1-31).
M: month (1-12).
D: the day of the week (0600 is Sunday).
The program to be run by cmd, which is sent to sh for execution. This shell has only three environment variables, USER,HOME,SHELL.
Description:
Crontab is used to allow users to execute programs at fixed times or at regular intervals, in other words, similar to the user's schedule. -u user refers to setting and specifying
User's schedule, this premise is that you must have its permissions (such as root) to be able to specify someone else's schedule. If you don't use-u user, it means set
Set your own schedule.
Parameters:
Crontab-e: execute a text editor to set the schedule. The internal text editor is VI. If you want to use another text editor, please set the VISUAL environment variable first.
To specify which text editor to use (such as setenv VISUAL joe)
Crontab-r: delete the current schedule
Crontab-l: list the current schedule
Crontab file [- u user]-replaces the current crontab with the specified file.
The format of the schedule is as follows:
F1 f2 f3 f4 f5 program
Where F1 represents minutes, f2 represents hours, f3 represents the day of a month, f4 represents a month, and f5 represents the day of a week. Program means to hold on.
The program of the line.
When F1 is *, it means that every minute will be executed. If program,f2 is *, the program will be executed every hour, and so on.
When F1 is aMub, it will be executed from minute a to minute b, and when f2 is amelb, it will be executed from hour a to hour b, and so on.
When F1 is * / n, it is executed every n minutes, f2 is * / n, it is executed every n hours, and so on.
When F1 is a, b, c. It means a, b, c, etc. Minutes to be executed, f2 is a, b, c. It means a, b, c. Hours to execute, other analogies
Users can also store all the settings in the file file and set the schedule in the way of crontab file.
Example:
# execute / bin/ls once every morning at 7 am:
0 7 * / bin/ls
/ usr/bin/backup is performed every 3 hours from 6 a.m. to 12:00 every December:
0 6-12 beat 3 * 12 * / usr/bin/backup
Send a letter to alex@domain.name at 5:00 every day from Monday to Friday:
0 17 * 1-5 mail-s "hi" alex@domain.name
< /tmp/maildata 每月每天的午夜 0 点 20 分, 2 点 20 分, 4 点 20 分....执行 echo "haha" 20 0-23/2 * * * echo "haha" 注意 : 当程序在你所指定的时间执行后,系统会寄一封信给你,显示该程序执行的内容,若是你不希望收到这样的信,请在每一行空一格之 后加上 >/ dev/null 2 > & 1 is fine.
Example 2:
# 06:10 every morning
10 6 * date
# every two hours
0 * / 2 * date
# every two hours between 11:00 and 8 a.m., 8 a.m.
023-7bat 2pm 8 * date
# on the 4th of every month and 11:00 from Monday to Wednesday
0 11 4 * mon-wed date
# 4: 00 a. M. in January
0 4 1 jan * date
Example
$crontab-l lists the user's current crontab.
At this point, the study on "how to use crontab" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.