1.crontab介绍
crontab命令设置定时任务执行的时间规则,系统自动周期性执行命令。
这里我们就可以自定义脚本,然后设置定时执行脚本,达到我们想要在服务器定时执行的目标。
2.crontab相关命令
检查当前任务列表,同时查看是否安装了crontab
crontab -l
编辑任务列表,添加删除新任务。执行命令后会打开文件,vim操作编辑保存文件,文件中每一行代表一条任务。
crontab -e
3.crontab格式
格式:时间规则 + 执行命令

定时任务规则
时间格式参数有5位,分表表示:
分钟0-59,小时0-23,日1-31,月1-12,星期0-6

crontab定时任务执行的脚本
auto-del-1-day-ago-log.sh脚本

网友评论