linux定时任务crontab

linux定时任务crontab 主要是做一些周期性的任务,比如凌晨2点定时备份某些数据等。

计划任务主要分为以下两种使用情况:

1.系统级别的定时任务

临时文件清理、系统信息采集、日志文件切割

2.用户级别的定时任务

定时向互联网同步时间、定时备份系统配置文件、定时备份数据库的数据。

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) * 表示任意的(分、时、日、月、周)时间都执行
2) - 表示一个时间范围段, 如5-7点
3) , 表示分隔时段, 如6,0,4表示周六、日、四
4) /1 表示每隔n单位时间, 如*/10 每10分钟

crontab命令
-e : 执行文字编辑器来设定时程表
-r : 删除目前的时程表
-l : 列出目前的时程表

1.crontab -e 编写定时任务
*/5 * * * * /bin/sh /home/mytest/out.sh 每隔五分钟执行一次out.sh文件

2.启动服务 service crond restart






posted @ 2020-02-26 14:15  架构之路  阅读(211)  评论(0编辑  收藏  举报
========================================================================== 如果您觉得这篇文章对你有帮助,可以【关注我】或者【点赞】,希望我们一起在架构的路上,并肩齐行 ==========================================================================