Edit: crontab -u root -e
List: crontab -u root -l
Delete: crontab -u root -r
Every five minutes to perform * / 5 * * * *
Hourly execution 0 * * * *
Execution day 00 * * *
Weekly perform 00 * 0 *
The implementation of 001 per month * *
Implementation of 0011 per year *
*/1 * * * * ls >>/tmp/ls.txt
1. Role
Use crontab crontab command to modify the configuration file, which is then executed by the cron configuration utility at the appropriate time, the command uses the permissions for all users.
2. Format
crontab [-u user] {-l | -r | -e}
3. The main parameters
-e: performing a text editor to set the time-table, the text editor is empty vi
-r: delete the current time-table
-l Lists the current time-table.
Crontab file format as "MHD md cmd". Wherein, M for minutes (0 ~ 59), H is hours (0 ~ 23), D for days (1 to 31), days (0-6 m represents the month (1 ~ 12), d representative of one week, 0 is Sunday). Cmd indicates that the program to run, it is sent to sh executed, the shell only USER, HOME, SHELL three environment variables.
Use cron service, view the cron service status with server crond status, if not start the service crond start to start it, cron service is a regular implementation of the service, you can add or edit the regular implementation of the tasks required by the crontab command:
crontab -u // set a user's cron service, usually root user needs this parameter when executing this command
crontab -l // set out in detail the contents of a user cron services
crontab -r // delete a user's cron service
crontab -e // edit a user's cron service
crontab filename // filename to a crontab task list file and load
For example, set the root view their own cron: crontab -u root -l
For another example, root want to delete the cron setting fred: crontab -u fred -r
When editing cron service, edit the contents of some of the formats and conventions, enter: crontab -u root -e
Enter vi edit mode, edit the content must meet the following format:
*/1 * * * * ls >>/tmp/ls.txt
Edit / etc / crontab file, add a line at the end: 30 5 * * * root init 6 will configure the system so every morning to 5:30 automatically restart.
crontab file rows of six fields, separated by a space or tab between the different fields. Top 5 field specifies the command to run time
Min (0-59)
Hour (0-23)
Date (1-31)
Month (1-12)
Day of the week (0-6, where 0 = Sunday, 7 seems also represents Sunday)
The sixth field is a string to be executed at the appropriate time.
example:
#MIN HOUR DAY MONTH DAYOFWEEK COMMAND
# Every morning 6:10
10 6 * * * date
# Every two hours
0 */2 * * * date
# Evening between 11:00 to 8:00 in the morning every two hours, 8:00 am
0 23-7/2,8 * * * date
# 4th of every month and every Monday morning to Wednesday 11:00
0 11 4 * 1-3 date
# January 1 4:00 am
0 4 1 1 * date
NOTE: When using crontab, paying particular attention is to run a script to access to environment variables and the current test environment environment variable does not necessarily agree a safer practice is to script the running set environment variables yourself (export )
(1) first built a file crond.txt follows every morning 5:36 to restart
36 5 * * * reboot
(2) uploaded to the / opt directory
(3) Run the command
crontab /opt/crond.txt
crontab –l
Let configuration file to take effect: If the configuration file to take effect, have to restart cron, remember, since the cron configuration file under each user modifications, but also to restart the cron server.
In Fedora and Redhat, we should use:
/etc/rc.d/crond restart
If you let the crond to run at boot time, you should change its run level:
chkconfig –level 35 crond on
service crond status view the cron service status, if not start the service crond start to start it, cron service is a regular implementation of the service, you can add or edit the crontab command by the need to perform regular tasks