linux命令之crontab定时执行任务

时间:2021-06-26 07:56:16

 

参考:http://www.cnblogs.com/coffy/p/5608095.html

 

  

一、crond简介

crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动crond进程,crond进程每分钟会定期检查是否有要执行的任务,如果有要执行的任务,则自动执行该任务。

Linux下的任务调度分为两类,系统任务调度和用户任务调度。

系统任务调度:系统周期性所要执行的工作,比如写缓存数据到硬盘、日志清理等。在/etc目录下有一个crontab文件,这个就是系统任务调度的配置文件。

 

二、案例

SHELL=/bin/bash
PATH
=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO
=root
HOME
=/

# For details see man
4 crontabs

# Example of job definition:
# .
---------------- minute (0 - 59)
#
| .------------- hour (0 - 23)
#
| | .---------- day of month (1 - 31)
#
| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
#
| | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#
| | | | |
#
* * * * * user-name command to be executed


# 每5分钟执行一次autoComment
*/5 * * * * root /usr/bin/curl http://api.xxx.com/Cron/Cron/index/method/autocomment.html

# 每5分钟执行一次autopaybus
*/5 * * * * root /usr/bin/curl http://api.xxx.com/Cron/Cron/index/method/autopaybus.html