Linux CentOS Scheduled Task scheduled task crontab

Source: Internet
Author: User

1. View the self-launch list

chkconfig --list(centos6)systemctl is-enabled crond.service (centos7)

2. See if it is currently started

ps aux | grep crond

3, start and set to self-start (crontab generally for the system self-boot, do not need to set up the following)

启动:service crond restart(centos6),systemctl start crond.service(centos7)设置为自启动:chkconfig crond on (centos6),systemctl enable crond.service(centos7)

4. Using crontab
crontab [Options]
Options:
-E: Editing crontab timed tasks
-L: Query crontab task
-R: Delete all crontab tasks for the current user

5. Edit Crontab

#进入crontab编辑界面。会打开vim编辑你的工作。格式如:* * * * * 执行的任务或脚本(绝对路径)第一个“ *”: 一小时当中的第几分钟:0-59第二个“ *”: 一天当中的第几小时:0-23第三个“ *”: 一个月当中的第几天:1-31第四个“ *”: 一年当中的第几月: 1-12第五个“ *”: 一周当中的星期几 :0-7( 0和7都代表星期日)* 代表任何时间。 比如第一个“ *” 就代表一小时中每分钟都执行一次的意思。, 代表不连续的时间。 比如“ 0 8,12,16 * * * 命令” ,就代表在每天的8点0分, 12点0分, 16点0分都执行一次命令- 代表连续的时间范围。 比如“ 0 5 * * 1-6命令” ,代表在周一到周六的凌晨5点0分执行命令*/n 代表每隔多久执行一次。 比如“ */10 * * * * 命令” , 代表每隔10分钟就执行一遍命令

6. Example

5 22 * * * 命令 :在22点5分执行命令0 17 * * 1 命令 :每周1 的17点0分执行命令0 5 1,15 * * 命令 :每月1号和15号的凌晨5点0分执行命令40 4 * * 1-5 命令 :每周一到周五的凌晨4点40分执行命令*/10 4 * * * 命令 :每天的凌晨4点, 每隔10分钟执行一次命令0 0 1,15 * 1 命令 :每月1号和15号, 每周1的0点0分都会执行命令。 注意:星期几和几号最好不要同时出现(同时出现时,作用等于or), 因为他们定义的都是天,非常容易混乱。*/5 * * * * /bin/echo ”11” >> /tmp/test:每5分钟将“11”写入test文件5 5 * * 2 /sbin/shutdown -r now:每周二5点5分重启0 5 1,10,15 * * /root/sh/autobak.sh:每月1、10、15号的凌晨5时整执行此脚本

Linux CentOS Scheduled Task scheduled task crontab

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.