2.6 scheduled tasks
In Linux, there are two types of scheduled tasks: one is to execute only one at scheduled task, and the other is to execute cron scheduled tasks cyclically.
2.6.1 at one-time scheduled task
Before using at to specify a one-time scheduled task, make sure that the atd service is enabled. Otherwise, the scheduled task is not executed. Use Service ATD start to enable the service and use chkconfig ATD on to ensure that the service starts up.
At
Description: executes a specific command at a specified time.
Usage: At time
Option:-M: send an email to the user after the scheduled task is executed.
-L view User scheduled tasks
-D. delete a user scheduled task.
-C. view the specific content of the at scheduled task
[[email protected] ~]# at 1213at> ls -l /tmpat> <EOT> (Ctrl+D)job 7 at 2014-08-15 12:13
The at command can be used in many time formats, such as at hour: minute (the default time is the current day), at 4 + 3 days (the scheduled task is executed at four o'clock P.M. after 3 days ), at (scheduled tasks for the specified year, month, day, and date). For more information, see at help.
2.6.2 cron periodic scheduled tasks
Make sure that the crond service is enabled before you use cron to specify a one-time scheduled task. Otherwise, the scheduled task is not executed. Use Service crond start to start the service and use chkconfig crond on to ensure that the service starts up.
Crontab
Description: maintenance of periodic scheduled tasks for each user.
Usage: crontab [-u user] [-L |-r |-E]
Option:-u indicates the user who schedules the task. The default value is the current user.
-L view scheduled tasks
-R: delete a scheduled task.
-E: edit a scheduled task
-I ask the user to confirm the deletion when using-R to delete a scheduled task
Table 2-8
First column |
Column 2 |
Column 3 |
Column 4 |
Column 5 |
Column 6 |
Minute |
Hour |
Day |
Month |
Week |
Command |
00 ~ 59 |
00 ~ 23 |
1 ~ 31 |
1 ~ 12 |
0 ~ 7 (0 and 7 represent Sunday) |
|
If you want to specify a time period, you can use a horizontal bar (-) to indicate a period of continuous time, use a comma (,) to indicate several discontinuous times, and use an asterisk (*) indicates all the time, and (/) indicates the interval.
[[email protected] ~]# crontab -e50 12 15 8 * /usr/bin/free | mail -s "Mem" root
The centos system customizes many scheduled task scripts, which are respectively stored in cron under/etc. daily/, cron. hourly/, cron. monthly/, cron. in the weekly/directory, if you have a script that needs to be executed every day, you can store the script in cron. in the daily/directory, the system automatically runs the script for you every day.
2.6.3 scheduler task Permissions
In order to control users to define their own scheduled tasks, the administrator can perform ACL Access Control. The control files of at scheduled tasks are/etc/. allow and/etc/. deny. The default value is. allow does not exist. The control files of cron scheduled tasks are/etc/cron. allow and/etc/cron. deny. By default, cron. allow does not exist.
You only need to write the user name to the control file, with one user name in one row. When the Allow file exists, only users in the Allow file can use the corresponding scheduled task, if the Allow file and the deny file have the same account at the same time, you can use the scheduled task only for users that appear in allow. If there is no allow file but only the deny file, all users that appear in the deny cannot use the scheduled task, and all other users can use the scheduled task.