Crontab start, run, and edit view
The cron service is a built-in service for Linux, but it does not boot automatically. You can start and stop the service with the following command:
/sbin/service Crond Start
/sbin/service Crond Stop
/sbin/service Crond Restart
/sbin/service Crond Reload
The above 1-4 lines start, stop, restart the service, and reload the configuration, respectively.
To set cron to start automatically when booting, in the/etc/rc.d/rc.local script can be added /sbin/service crond start
View current user's crontab, enter crontab-l;
Edit Crontab, enter crontab-e;
Delete crontab, enter Crontab-r
The use of crontab under Linux
Execute */5 every five minutes * * * *
Executes 0 per hour * * * *
Executes 0 0 * * * per day
Weekly Execution 0 0 * 0
Monthly execution 0 0 1 * *
Annual Execution 0 0 1 1 *
For detailed usage, refer to this blog post http://yangqijun.iteye.com/blog/1173016
1. Role
Use the crontab command to modify the crontab configuration file, and then the configuration is performed by the Cron utility at the appropriate time, and the command usage permission is for all users.
2. Format
crontab [-u user] {-l |-r |-e}
3. Main parameters
-E: Executes the text editor to set the time table, the empty text editor is VI
-R: Delete the current schedule table
-l lists the current schedule table.
The format of the crontab file is "M H d M D cmd". where m stands for minutes (0~59), H for hours (0~23), D for Day (1~31), M for month (1~12), d for Day of week (0~6,0 for Sunday). CMD represents the program to be run, it is sent to sh execution, the shell only user, HOME, shell three environment variables.
Use the Cron service to view the Cron service status with the server Crond status, if it is not started, service Crond start starts it, and the cron service is a timed execution service. You can add or edit tasks that need to be performed on a timed basis through the crontab command:
Crontab–u//Set a user's Cron service, which is usually required by the root user when executing this command
Crontab–l//list details of a user cron service
Crontab–r//Delete a user's cron service
Crontab–e//Edit a user's cron service
crontab filename//with filename as the crontab task list file and load
For example, root to view your cron settings: Crontab–u root–l
Again, for example, Root wants to delete Fred's cron settings: Crontab–u fred–r
When editing the Cron service, the edited content has some formatting and conventions, input: Crontab–u root–e
To enter the vi editing mode, edit the content must conform to the following format:
*/1 * * * * ls >>/tmp/ls.txt
Edit the/etc/crontab file and add a line at the end: 5 * * * Root init 6 This configures the system to automatically restart 5:30 A.M. every day.
The rows in the crontab file consist of 6 fields separated by a space or TAB key between the different fields. First 5 fields specify when the command will run
Minutes (0-59)
Hours (0-23)
Date (1-31)
Month (1-12)
Day of the week (0-6, of which 0 stands for Sunday, as if 7 also represents Sunday)
The 6th field is a string to execute at an appropriate time.
Example:
#MIN HOUR Day MONTH DAYOFWEEK COMMAND
#每天早上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
Add: When using crontab, it is important to note that the environment variables that are accessible in the run script are not necessarily consistent with the environment variables in the current test environment, and it is safer to set the environment variables yourself in a running script (export)
(1) First build a file Crond.txt as follows, restart 5:36 A.M. every day
5 * * * reboot
(2) Upload to/opt directory
(3) Run the command
Crontab/opt/crond.txt
Crontab–l
Let the configuration file take effect: If you let the configuration file take effect, and you have to restart Cron, remember, since the Cron profile under each user has been modified, you will have to restart the cron server.
In Fedora and redhat, we should use:
/etc/rc.d/crond restart
Crontab start, run, and edit view