1.crontab
2.Linux下实现秒级定时任务的三种方案(crontab 每秒运行)
3.apscheduler 定时任务框架(python实现)
1.定时模块crontab
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
定时文件有两个地方
1.crontab -e 用户定时任务,每个用户都有一个对应的crontab 文件,在/var/spool/cron/ 下
/etc/crontab 这个是系统定时文件,不会根据用户不同而改变
注意:
定时任务的时候尽量写绝对路径
尽量不要用 crontab crontab_file 以免覆盖 当前用户的定时任务 源文件
遇到的问题:
1.crontab 没有生效
检查crontab是否启动
centos: /etc/init.d/crond status
/etc/init.s/crond restart
vi /etc/crontab 中, 要加执行用户username * * * * *