1. Overview
Crontab is used to set the execution of an instruction at a fixed point in time or at a time interval, similar to a schedule table. Use-u user is the time table for specifying user users.
2. Parameters
-e[username]: Bring up the editor, edit timed tasks, open the inside there is a multi-text editor, can have their own preferences, if not specified UserName, is the current shell user
-r[username]: Deletes the current time table for the specified user, which is the user under the current shell
-l[username]: Lists the current schedule table for the specified user, which is the user under the current shell
-v[username]: Lists the cron job status for the specified user, which is the user under the current shell
3. Format description of the time schedule table
F1 F2 F3 F4 F5 program (minutes of small days and weeks of homework orders)
For example: 5 */1 * * */usr/sbin/ntpdate CMS is the command that executes/usr/sbin/ntpdate CMS in the first 5 minutes of every hour.
Description See:
4. Examples
#每天早上6点10分
6 * * * Date
#每两个小时
0 */2 * * * Date
#晚上11点到早上8点之间每两个小时, 8 in the morning.
0 23-7/2,8 * * * Date
#每个月的4号和每个礼拜一到礼拜三的早上11点
0 4 * 1-3 date
#1月1日早上4点
0 4 1 1 * Date
Be aware of the current environment variables when writing execution commands.
5, with sleep to achieve second-level timing
If you execute directly on the terminal:
3s;/bin/date
It is obvious that sleep can delay execution of the command, then the second level of timing is achieved with crontab, as follows:
* * * * * * Sleep 10s; /bin/date >>/tmp/date.txt* * * * * * sleep 20s; /bin/date >>/tmp/date.txt* * * * * * sleep 30s; /bin/date >>/tmp/date.txt* * * * * * sleep 40s; /bin/date >>/tmp/date.txt* * * * * * sleep 50s; /bin/date >>/tmp/date.txt
When observing/temp/date.txt, you can see a time record every 10 seconds.
Of course, sleep time units also have points, hours, days (M, H, D), and in this case only seconds are used.
"Timers" under Linux: Crontab