Suse Linux Crontab

基本概念


Crontab  类似于Windows 里的task schedule ,是一种定时执行工具 .能够在确定的时间执行确定的任务(脚本)。
Crontab 是linux系统里的一个守护进程 ,会随着系统的启动而启动。

基本操作


/sbin/service cron start        启动crontab
/sbin/service cron stop        停止crontab
/sbin/service cron restart     重新启动crontab
/sbin/service cron reload     重新载入crontab
crontab -l  (列出当前用户的crontab list)
crontab -u root -l  (列出root  用户的 list)
crontab crontab.txt  (载入一个文本文件,替换成当前的crontab  list)
crontab -e  (编辑crontab list)
当前激活的 crontab : /var/spool/cron/tabs
man 5 crontab  详细帮助信息

在etc下,有以下几个目录,把对应的脚本放入其中,那么就每隔一段时间执行当前脚本,不需要额外配置
/etc/cron.daily    
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

参数说明


 分     小时        日       月        星期          命令
 0-59   0-23   1-31   1-12     0-6     command    
(取值范围,0表示周日一般一行对应一个任务) 
特殊符号的含义: 
  • "*"代表取值范围内的数字,
  • "/"代表"每", 
  • "-"代表从某个数字到某个数字,
  •  ","分开几个离散的数字


基本流程


  1. 导出已有的crontab list , 命令:crontab -u root -l >> crontab.txt
  2. 编辑 crontab.txt 
  3. 导入编辑好的文件 :crontab  crontab.txt
  4. 重启cron : /sbin/service cron restart  

实际例子


#----------------------------------------------------
# fields: minute hour day-of-month month day-of-week
# Sunday is 7
# More info:  man 5 crontab
# As root:  crontab -l  (list current)
#           crontab crontab.txt  (to load changes)
#           crontab -e  (or to edit/replace current)
# Active crontab is located in: /var/spool/cron/tabs
#
# Change log
#
#---------------------------------------------------
MAILTO="xxxx@xxx.com"
PATH=/opt/build/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin:


#--- New jbe log -------------------------------------------------
30 23 * * 5 /opt/build/bin/jbe_restart >> /opt/build/logs/cron.log 2>&1

#--- Keep GSA mounted --------------------------------------------
*/15 0-19 * * * /opt/build/bin/gsa_chkmount >> /opt/build/logs/cron.log 2>&1
*/15 20-23 * * 0-4,6 /opt/build/bin/gsa_chkmount >> /opt/build/logs/cron.log 2>&1
#--- BSO bust-out ------------------------------------------------
0  5,18 * * * ruby /opt/build/bin/appease_bso >> /opt/build/logs/cron.log 2>&1
@reboot ruby /opt/build/bin/appease_bso >> /opt/build/logs/cron.log 2>&1

Reference

http://os.51cto.com/art/200512/13558.htm
http://wenku.baidu.com/view/c06ca5a4b0717fd5360cdc9d.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值