In Linux you should first enter CRONTAB-E, then there will be a VI editing interface, and then enter 0 3 * * 1/clearigame2 content into the inside: Wq save exit.
In Linux, the tasks performed by the cycle are typically handled by the cron Daemon (ps-ef|grep cron). Cron reads one or more configuration files that contain the command line and its invocation time.
The cron configuration file is called "crontab" and is shorthand for "cron table".
First, cron find the configuration file in 3 places:
1,/var/spool/cron/This directory is stored in each user including root crontab task, each task is named after the creator, such as Tom built crontab task corresponding to the file is/var/spool/cron/tom.
Generally, a user has only one crontab file at most.
/etc/crontab This document is responsible for arranging the crontab of maintenance systems and other tasks developed by the system administrator.
/etc/cron.d/This directory is used to store any crontab files or scripts to be executed.
Iv. Permissions
Crontab permissions issue to/var/adm/cron/next look, file Cron.allow and Cron.deny exist
Use the following:
1. If none of the two files exist, only the root user can use the crontab command.
2, if the Cron.allow exists but Cron.deny does not exist, only the users listed in the Cron.allow file can use the crontab command, if the root user is not inside, then the root user can not use crontab.
3, if the Cron.allow does not exist, Cron.deny exist, only the users listed in the Cron.deny file can not use the crontab command, other users can use.
4, if two files exist, then listed in the Cron.allow file and not listed in Cron.deny users can use crontab, if two files have the same user,
If the user is in the Cron.allow file, you can use the crontab command if there is a user in the Cron.allow.
How to enter the command and time to execute in the crontab file. Each row in the file contains six fields, the first five of which are the time the specified command was executed, and the last field is the command to be executed.
Spaces or tabs are used to separate each field. The format is as follows:
Minute hour day-of-month month-of-year day-of-week commands
Legal value 00-59 00-23 01-31 01-12 0-6 (0 is Sunday) commands (represents the script to be executed)
In addition to the numbers there are several special symbols that are "*", "/" and "-", ",", * represent all the values within the range of the number, "/" for each meaning, "/" for each of the 5 units, "-" represents from a number to a number, "," separate several discrete numbers.
Basic format:
Command
Time-sharing Weekly command
The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run
Some examples of crontab files:
#每晚的21:30 Restart Apache.
* * * * */usr/local/etc/rc.d/lighttpd restart
#每月1, 10, 22nd
4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart
#每天早上6点10分
6 * * * Date
#每两个小时
0 */2 * * * Date
#晚上11点到早上8点之间每两个小时, 8 in the morning.
0 23-7/2,8 * * * Date
#每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点
0 4 * mon-wed date
#1月份日早上4点
0 4 1 Jan * Date
Many times, we plan a task that needs to be done in seconds, and it's easy to perform tasks in seconds, depending on the following methods. The following methods will
executes once every 10 seconds
1234567 |
# crontab -e
*
*
*
*
*
/
bin
/
date >>
/
tmp
/
date.txt
*
*
*
*
*
sleep
10
;
/
bin
/
date >>
/
tmp
/
date.txt
*
*
*
*
*
sleep
20
;
/
bin
/
date >>
/
tmp
/
date.txt
* *
*
*
*
sleep
30
;
/
bin
/
date >>
/
tmp
/
date.txt
*
*
*
*
*
sleep
40
;
/
bin
/
date >>
/
tmp
/
date.txt
*
* *
*
*
sleep
50
;
/
bin
/
date >>
/
tmp
/
date.txt
|
Note that if you use% for the command, you need to escape
123 |
# backup mysql
00
01
*
*
*
mysqldump
-
u root
-
-
password
=
passwd
-
d mustang >
/
root
/
backups
/
mustang_$(date
+
\
%
Y\
%
m\
%
d_\
%
H\
%
M\
%
S).sql
01 01
*
*
*
mysqldump
-
u root
-
-
password
=
passwd
-
t mustang >
/
root
/
backups
/
mustang
-
table_$(date
+
\
%
Y\
%
m\
%
d_\
%
H\
%
M\
%
S).sql
|
Linux Crontab Scheduled Task script