First, check the related services
1. Check Crond Service
Service Crond Status
Installation Services
Yum Install Vixie-cron
2. Check the crontab Configuration tool
Crontab-l
Installing crontab
Yum Install Crontabs
Second, set up the Scheduled tasks
1. View existing Plans
[Email protected] ~]# crontab-l/*1date >>/tmp/log.txt*/1 SleepDate >>/tmp/log.txt
Each row represents a plan. There are 5 on the left of each row * indicates the code to be executed to the right of the scheduled execution time.
Explanation of 5 * In the crontab configuration file.
[Email protected] ~]#Cat/etc/crontab SHELL=/bin/Bashpath=/sbin:/bin:/usr/sbin:/usr/Binmailto=Roothome=/# for details seeMans 4crontabs# Example of Job definition:#.----------------Minute (0- -)# | .-------------Hour (0- at)# | | .----------Day of Month (1- to)# | | | .-------Month (1- A) OR jan,feb,mar,apr ... #| | | | .----Day of Week (0-6) (sunday=0Or7) OR sun,mon,tue,wed,thu,fri,sat#| | | | |# * * * * * * user-name command to be executed
As you can see from the above explanation, the minimum execution time for each plan can only be set to one execution per minute. So how do you set up a schedule that executes every 30s, by setting two identical plans, but the second one will sleep 30s at the time of execution.
2. Editorial Plan
Crontab-e
3. Here are a few simple examples
Executes once per minute.
* * * * * command
Executes every 30 minutes.
0, * * * * command
Every day from 9 to 10 points in the first 1 minutes of execution.
1 9-Ten * * * command
Every 2 days, 10 points of the first 1 minutes of execution.
1 Ten */2 * * command
4. Special symbolic interpretation of the above example
*: represents all possible values.
,: Specify a list range, for example, "1,3,5,7,9"
-: Specifies an integer range, for example, "1-5" for "1,2,3,4,5"
/: The interval frequency of the specified time, for example, "0-23/2", is performed every two hours.
5. View the log for scheduled execution
cat /var/log/: run-parts localhost(/etc/cron.daily ) [1277]: finished logrotate
Third, the matters needing attention
1. Write global path when file path is involved in command.
2, the system automatically perform task scheduling, is not loaded any environment variables.
Scheduled Tasks for Linux