crontab set to execute every minute hour day week month year

crontab is executed every minute

*/1 * * * * service mysqld restart //execute every 1 minute
*/10 * * * * service mysqld restart //execute every 10 minutes

crontab executes every hour:

0 */1 * * * service mysqld restart //execute every 1 hour
0 */2 * * * service mysqld restart //execute every 2 hours

crontab executes regularly every day:

0 10 * * * service mysqld restart //execute at 10 o'clock every day
30 19 * * * service mysqld restart //execute at 19:30 every day

crontab executes regularly every week:

0 10 * * 1 service mysqld restart //Execute every Monday at 10:00
30 17 * * 5 service mysqld restart //Execute every Friday at 17:30

crontab executes regularly every year:

0 10 1 10 * service mysqld restart //Execute at 10:00 on October 1st every year
0 20 8 8 * service mysqld restart //execute at 20:00 on August 8 every year

other

1. Regularly execute the rule every minute:
Execute every 1 minute: */1 * * * * or * * * * *
Execute every 5 minutes: */5 * * * *
2. Regularly execute the rules every hour:
Execute every hour: 0 * * * * or 0 */1 * * *
Executed daily at 7am: 0 7 * * *
Executed daily at 7:10am: 10 7 * * *
3. Regularly execute the rules once a day:
Execute every day 0 0 * * *
4. Regularly execute the rules once a week:
Execute weekly 0 0 * * 0
5. Regularly execute the rules once a month:
Monthly execution 0 0 1 * *
6. Regularly implement the rules once a year:
Annually 0 0 1 1 *
7. Other Examples
5 * * * * Specifies to execute the ls command every 5th minute of every hour
30 5 * * * ls Specifies to execute the ls command at 5:30 every day
30 7 8 * * ls Specifies to execute the ls command at 7:30 on the 8th of each month
30 5 8 6 * ls Specifies to execute the ls command at 5:30 on June 8 every year
30 6 * * 0 ls Specifies to execute the ls command at 6:30 every Sunday [Note: 0 means Sunday, 1 means week 1, and so on, and can also be expressed in English, sun means Sunday, mon means Monday, etc. ]
30 3 10,20 * * ls Execute the ls command at 3:30 on the 10th and 20th of every month [Note: "," is used to connect multiple discontinuous time periods]
25 8-11 * * * ls Execute the ls command at the 25th minute of 8-11 o'clock every day [Note: "-" is used to connect consecutive time periods]
*/15 * * * * ls executes the ls command every 15 minutes [that is, executes the ls command at the 0th 15th 30th 45th 60th minute of every hour]
30 6 */10 * * ls Every month, execute the ls command at 6:30 every 10 days [that is, execute the ls command at 6:30 on the 1st, 11th, 21st, and 31st of each month. ]
0 10 * * 1-3 /home/postgres/pgsql.sh
Indicates that the script is executed every Monday to Wednesday at 10:00 in the morning
0 10 * * 1, 3, 5 /home/postgres/pgsql.sh
Indicates that the script is executed every Monday, Wednesday, and Friday at 10:00 in the morning
A cron expression has at least 6 (and possibly 7) time elements separated by spaces.
in order of
Seconds (0~59)
minutes (0~59)
hour (0~23)
Day (month) (0~31, but you need to consider the number of days in your month)
Month (0~11)
Day (week) (1~7 1=SUN or SUN, MON, TUE, WED, THU, FRI, SAT)
Year (1970-2099)
where each element can be a value (such as 6), a continuous interval (9-12), an interval (8-18/4) (/ means every 4 hours), a list (1,3,5) , wildcard. Since the two elements "day of the month" and "day of the week" are mutually exclusive, must one be set?
0 0 10, 14, 16 * * ? 10am, 2pm, 4pm daily
0 0/30 9-17 * * ? every half hour during 9 to 5 working hours
0 0 12 ? * WED means every Wednesday at 12 noon
"0 0 12 * * ?" fires at 12 noon every day
"0 15 10 ? * *" fires at 10:15 am every day
"0 15 10 * * ?" fires every day at 10:15 am
"0 15 10 * * ? *" fires at 10:15 am every day
"0 15 10 * * ? 2005" fires at 10:15 am every day in 2005
"0 * 14 * * ?" fires every 1 minute between 2pm and 2:59pm every day
"0 0/5 14 * * ?" fires every 5 minutes between 2pm and 2:55pm every day
"0 0/5 14,18 * * ?" fires every 5 minutes from 2pm to 2:55pm and from 6pm to 6:55pm every day
"0 0-5 14 * * ?" fires every 1 minute between 2pm and 2:05pm every day
"0 10,44 14 ? 3 WED" fires every March Wednesday at 2:10pm and 2:44pm
"0 15 10 ? * MON-FRI" fires at 10:15 am Monday to Friday
"0 15 10 15 * ?" fires at 10:15 am on the 15th of every month
"0 15 10 L * ?" Fires at 10:15 am on the last day of every month
"0 15 10 ? * 6L" fires at 10:15 am on the last Friday of every month
"0 15 10 ? * 6L 2002-2005" Fires at 10:15 am on the last Friday of every month from 2002 to 2005
"0 15 10 ? * 6#3" fires at 10:15 am on the third Friday of every month
45 22 ***Order Execute the order at 22:45
0 17 ** 1 command to execute the command every Monday at 17:00
0 5 1, 15**Command Execute the command at 5:00 AM on the 1st and 15th of each month
40 4 ** 1-5 Commands Execute commands at 4:40AM every Monday through Friday
*/10 4 ***Command executes the command every 10 minutes at 4am every day
0 0 1, 15 * 1 command On the 1st and 15th of each month, the command will be executed at 0:00 every week. Note: It is best not to appear on the day of the week and the day of the week, because they all define days, very Easy to confuse administrators

Leave a Reply

Your email address will not be published.

en_USEnglish