Linux crontab定时器
crontab -e 编辑定时器
crontab -l 显示当前定时器
crontab -r 删除当前定时器
格式 * * * * * command
分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 周(0-7,0和7都是星期日) 命令
辅助特殊字符:
* 表示任何时刻
,分割时间,只在周3和周5执行(* * * * 3,5 command)
- 时间端,在0到12小时内运行(* 0-12 * * * command)
/n n是数字,如果想每隔3分钟执行一次(*/3 * * * * command)
例如:将一个文件中的数据每隔三分钟执行追加到另一个文件中,只在每月的2号和4号运行
]# cat data
hello,everyone!
]# crontab -e
*/3 * 2,4 * * /bin/cat /root/data >> /root/dat
(编辑器保存后显示 crontab: installing new crontab)
]#cat dat (每个三分钟,数据会增加)
]#crontab -l (查看定时器)
]#crontab -r (删除定时器)