crontab 是用来让使用者(用户)在固定时间或固定间隔(即既定时间设置内)执行应用程序或代码。
命令示例:
查看当前用户的定时任务
[kettle@localhost sh]$ crontab –l
编辑当前用户的定时任务
[kettle@localhost sh]$ crontab –e
no crontab for ubuntu - using an empty one
Select an editor. To change later, run ‘select-editor‘.
1. /bin/ed
2. /bin/nano <---- easiest
3. /usr/bin/vim.basic
4. /usr/bin/vim.tinyChoose 1-4 [2]: 3 <<< This is ur choose. If chozen is not ur liked way use: select-editor
编辑当前用户的定时任务
[kettle@localhost sh]$ crontab –r
* * * * * command
分 时 日 月 周 命令
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启apache。
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重启apache。
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每周六、周日的1 : 10重启apache。
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启apache。
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重启apache。
- */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小时重启apache
- 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11点到早上7点之间,每隔一小时重启apache
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4号与每周一到周三的11点重启apache
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一号的4点重启apache
0 7 * * * /bin/ls
每天早上7点执行一次 /bin/ls
0 6-12/3 * 12 * /usr/bin/backup
在 12 月内, 每天的早上 6 点到 12 点中,每隔3个小时执行一次 /usr/bin/backup
0 17 * * 1-5 mail -s "hi" alex@domain.name < /tmp/maildata
周一到周五每天下午 5:00 寄一封信给 alex@domain.name
20 0-23/2 * * * echo "haha"
每月每天的午夜 0 点 20 分, 2 点 20 分, 4 点 20 分....执行 echo "haha"
原文:https://www.cnblogs.com/presleyren/p/11507650.html