cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业。我准备用cron来实现游戏排行榜定时更新,每日任务更新等等。

启动cron

ubuntu下是这样启动

/etc/init.d/cron start

顺便用sysv-rc-conf设置开机启动吧。

编辑/etc/crontab 文件配置cron

# 命令格式是:分钟(0~59) 小时(0~23) 日期(1~31) 月份(1~12) 星期(0~6,6是星期天) 执行用户 要执行的命令
* * * * * root /home/chao/script/hello.sh

好了现在重启cron就可以看效果了:

hello cron : 2012年 10月 10日 星期三 22:53:01 CST
hello cron : 2012年 10月 10日 星期三 22:54:01 CST
hello cron : 2012年 10月 10日 星期三 22:55:01 CST
hello cron : 2012年 10月 10日 星期三 22:56:01 CST
hello cron : 2012年 10月 10日 星期三 22:57:01 CST

附测试脚本:

#!/bin/sh
echo "hello cron : $(date)" >> /tmp/cron