System Scheduled Tasks
Most of the system administration work is done by automating a script on a regular basis, so you can automate your operations by executing a script on a regular basis, using the Cron functionality of Linux.
Scheduled tasks are divided into one-time scheduled tasks and recurring scheduled tasks.
- One-time Scheduled tasks
- 11 Shop 30 minutes per night Open website service.
- Recurring Scheduled Tasks
- Every Monday 3:30 A.M., the/var/www/html directory is packaged and backed up to backup.tar.gz
As the name implies, one-time scheduled tasks are performed only once and are generally used to meet temporary work requirements and can be at
implemented using commands.
If your Linux does not have this command can be used yum install at -y
to install.
[[email protected] ~]# at 23:30at> systemctl restart httpdat> <EOT>at > 此处同时按下Ctrl + D组合键来结束编写计划任务//查看已经设置好但还未执行的计划任务[[email protected] ~]# at -l1 Fri Aug 17 23:30:00 2018 a root//可以使用atrm任务序号删除[[email protected] ~]# atrm 1[[email protected] ~]# at -l
If you want Linux to be able to perform certain tasks periodically and regularly, then it is appropriate to use the crond
service.
If your Linux does not have this command can be used yum install cronie -y
to install.
Options |
explain |
Crontab-e |
Create and edit Scheduled Tasks |
Crontab-l |
View the current Scheduled tasks |
Crontab-r |
Delete a scheduled task |
Crontab-u |
Edit other people's scheduled tasks |
Note: This command uses the edited /var/spool/cron/username
file.
This command remembers the formula = = "Minute, time, day, month, week command" = = please keep in mind!!!
Field |
Description |
Score of |
An integer that takes a value of 0-59 |
When |
Any integer that takes a value of 0-23 |
Day |
Any integer that takes a value of 1-31 |
Month |
Any integer that takes a value of 1-12 |
Week |
The value is 0-7, where 0 and 7 are Sunday |
Command |
The command or program script to execute |
//每周一、三、五的凌晨3点30分打包/var/www/html目录[[email protected] ~]# crontab -ecrontab: installing new crontab[[email protected] ~]# crontab -l0 1 * * 1-5 /usr/bin/rm -rf /tmp/*30 3 * * 1,3,5 /usr/bin/tar -czvf backup.tar.gz /var/www/html
Memory Practice Examples
00 02 * * * ls //每天的凌晨2点执行ls00 02 1 * * ls //每月1号凌晨2点执行ls00 02 14 2 * ls //每年的2月的14号凌晨2点执行ls00 02 * * 7 ls //每周日凌晨2点执行ls00 02 * 6 5 ls //每年6月份周5的凌晨2点执行ls00 02 14 * 7 ls //每月周日或14号凌晨2点执行00 02 14 2 7 ls //每年2月14号或周日凌晨2点执行* 02 * * * ls //每天凌晨2点的每分钟执行* * 14 2 * ls //每年2月份14号每分钟执行* * * * * ls //每分钟执行*/5 * * * * ls //每5分钟执行00 02 * 1,5,8 * ls //每年1,5,8月的每天凌晨2点执行00 02 1-8 * * ls //每月的1-8号凌晨2点执行//这里需要注意的是分字段必须要求数值,不能为空或者*号//日和星期字段不能同时使用,否则会发生冲突//每周一到周五凌晨1点清空/tmp目录内的所有文件[[email protected] ~]# whereis rmrm: /usr/bin/rm /usr/share/man/man1/rm.1.gz[[email protected] ~]# crontab -l0 1 * * 1-5 /usr/bin/rm -rf /tmp/*
Linux Basic Learning-crond system Scheduled Tasks