例行性命令简单来说就是每隔一段时间就执行一次的操作或仅在指定时间执行一次以后就不再执行的操作。
1.仅执行一次
at 14:50 2013-03-12 /bin/sync shutdown -h now
使用atrm 删除计划 atrm 计划号
使用atq 查询所有计划
注释:在2013年3月12日下午14点50分关闭系统
2.重复执行
crontab 30 15 12 3 * shutdown -h now
每到3月12号 15点30分就执行关机
个人不喜欢这样操作,还有另外一种方法那就是编辑/etc/crontab文件,系统会每分钟读取该文件并执行定时任务
我系统中的/etc/crontab文件内容如下:
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )--每分执行
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) --每周日执行
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) --每天执行
20 15 * * * root mkdir /root/newsdir1 每天执行
#
格式:
分 时 日 月 周 执行用户 执行命令