Under the circumstances, we operate and operation of the VPS, the server may be used to crontab timing task configuration, such as the timing of the restart of the server, scheduled backup data and other operations using or more. This is inseparable from the use of the crontab command of the task configuration, in this article, the old left will be a more complete crontab command to use the method and commonly used instance operations.
From the above figure, we can actually see crontab specific usage. A total of 6 paragraphs, the first 5 marked timed time set, the next indicator of the path of the file is timed to execute.
First, crontab installation
Generally we use the CentOS or the Debian release version with the crontab timing software support, if the system does not support, we only need to install through the following corresponding.
1, CentOS installation crontab
The code is as follows |
Copy Code |
#安装Crontab
Yum Install Vixie-cron Crontabs
#设置开机启动Crontab
Chkconfig Crond on
#启动Crontab
Service Crond Start
|
2, Debian installation crontab
The code is as follows |
Copy Code |
#安装Crontab
Apt-get Install cron
#重启Crontab
/etc/init.d/cron restart
|
Make sure that the system is installed and running in effect before it can be related to the settings.
Update the database once every hour and 35 minutes.
2, */5 * * * * */usr/local/bin/diskusage.sh
Run diskusage.sh files every 5 minutes.
3, 25,50 1 * 2/usr/local/bin/diskusage.sh
1:50am Execution documents per Tuesday
4 3,6,9,12 */usr/local/bin/diskusage.sh
3, 6, 9, December, tenth day of the Year, 2 o'clock in the afternoon.
5 * * mon,wed,fri/usr/local/bin/diskusage.sh admin@laozuo.org
Execute scripts every Monday, five 9 o'clock in the afternoon
6, */5 * * * 1-5/usr/local/bin/diskusage.sh
Monday to Friday, executed every five minutes.
The code is as follows |
Copy Code |
/etc/cron.d/etc/cron.daily/etc/cron.hourly/etc/cron.monthly/etc/cron.weekly
|
If our root directory is executing the backup.sh backup command, use the above script to directly replace the/etc/cron.weekly directory.
Level setting of timing plan
When we operate, each user can edit, view, and delete the crontab timing profile. If the root user needs to change the crontab file, the '-u ' option must be added to specify the user name.
1, edit crontab file users Laozuo time, we can use the command:
2, remove the Laozuo user's timing setting
3, view Laozuo scheduled task settings file
Four, loading crontab from the file
In addition to manually editing a timed file, we can also load the file into a timed file.
The code is as follows |
Copy Code |
Cat/root/mycronjobs.txt
* * 7/bin/sh/root/server-backup.sh
* * * */bin/sh/root/check-user-quota.sh
|
We need to upload the edited Mycronjobs.txt timed task files to the directory before they can be executed.
The code is as follows |
Copy Code |
Crontab/root/mycronjobs.txt
|
Check validation with this command.
The code is as follows |
Copy Code |
Crontab-l
* * 7/bin/sh/root/server-backup.sh
* * * */bin/sh/root/check-user-quota.sh
|
Here we can check if the timed file exists.
Add SELinux security Options
The code is as follows |
Copy Code |
Crontab-s/root/mycronjobs/my.txt
selinux_role_type=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
* * 7/bin/sh/root/server-backup.sh
* * * */bin/sh/root/check-user-quota.sh
|
VI. Delete Timed task work
The code is as follows |
Copy Code |
[Root@linux ~]# Crontab-l
* * 7/bin/sh/root/server-backup.sh
* * * */bin/sh/root/check-user-quota.sh
[Root@linux ~]# Crontab-r
[Root@linux ~]# Crontab-l
No crontab for Root
|
We first use-l to view the current scheduled task, then use-R to delete, and then check that there are no task options.
Summary, the above 6 steps and methods, that is, we commonly used crontab timing file configuration commonly used, we will use a lot of backup and timed to start, according to our actual need to adjust the time.