On the Linux platform, you can write a Cron script to implement the task scheduling function.
Execute tasks at a certain frequencyBy default, the crond process is started in Linux. The crond process does not need to be started or closed.
The crond process reads and executes scheduling tasks. You only need to write the corresponding scheduling script to the cron scheduling configuration file.
Cron scheduling files include the following:
- Crontab
- Cron. d
- Cron. daily
- Cron. Hourly
- Cron. Monthly
- Cron. Weekly
If the task is not executed in hourly monthly weekly mode, you can write the corresponding crontab to the crontab or cron. d directory. Example:
Run the script every minute/opt/bin/test-cron.sh
You can create a script echo-date.sh in cron. d
Content is */1 * root/opt/bin/test-cron.sh
Run the task at the specified timeYou can also use the AT command to control the running tasks at the specified time, such as: At-F test-cron.sh-V
-F specifies the script file and-V specifies the running time.
Quote: ea946d690b = "lophyxp"] Use
Contab-L & gt; contabs. tmp
Export the contab configuration.
Edit the contabs. tmp file. Add a row in the following format:
Minute hour day month week command
For example
10 3 ** 0, 6 hello
The Hello program is executed at 03:10 every Saturday and Sunday.
15 4 ** 4-6 hello
The Hello program is executed from on Thursday to on Saturday.
Then use
Contab contabs. tmp
Command to import the new configuration.
Generally, it is not recommended to directly modify the relevant configuration files under/etc.
How to start the cron Process
:/Etc/init. d/crond start
Run the command chkconfig -- add crond to start the cron process at startup.
Method 2:
Add cron To the startup script:
# RC-update add vixie-cron default
Crontab-L # view your task
Crontab-e # edit your task
Crontab-R # Delete the user's crontab content
Example 2:
System cron settings:/etc/crontab
Through the/etc/crontab file, you can set the tasks that the system regularly executes. Of course, to edit this file, you must have the root permission 0 7 *** root mpg123 ~ /Wakeupyun
Example of hours, days, months, and Weeks: 0 4 ** 0
Root
Emerge-- Sync & emerge-ud world # updates the system at every Sunday.
0 2 1 ** Root
Rm-F/tmp/* # Clear files under/tmp at on the first day of every month
0 8 6 5 * Root
MailRobin 0 6, 12, 18 **** root ............... # execute at, and every day ........ 0 */2 * every two hours ***
Echo"Have a break now. "> & gt;/tmp/test.txt every two hours from PM to am, am, 8 *** echo "have a good dream :)" & gt; /tmp/test.txt every month and am from Monday to Wednesday of every week 4*1-3 command line AM, January 1, January 1 0 4 1 1 * command line
Gains: You can put some frequently-used tasks into it to simplify the workload, such as checking the server running status every Monday, viewing reports, and killing some processes ......