博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

crontab example.

Posted on 2013-05-21 13:54  钟悍  阅读(248)  评论(0编辑  收藏  举报

Example:

执行如下步骤创建一个crontab

1,# cd /opt/test/

2,先touch 文件 test-crontab.sh 内容如下(表示每分钟执行一次脚本/opt/test/test.sh)

      */1    *   *     *     *    /opt/test/test.sh

3, touch 文件 test.sh 内容如下

      echo "`date` hello" >> /opt/bin/dat.txt

4, chmod +x test-crontab.sh test.sh (加可执行权限)

5,执行下面启动该crontab

     # crontab test-crontab.sh

***************************************************************************

分         时       日        月       星期

*/1       *        *          *        *    /opt/test/test.sh    => 每1分钟执行test.sh

0       */2        *          *        *    /opt/test/test.sh    => 每2小时执行test.sh

30        9        *          *        *    /opt/test/test.sh    => 每天9点30分执行test.sh

0          8        *          *      1-5    /opt/test/test.sh    =>星期一到星期5的8点执行test.sh

*          *        *          *      */5    /opt/test/test.sh    => 每1分钟执行test.sh

**************************************************************************

#查看 [user用户下的] crontab

crontab [-u user] -l  

 

#删除 contab

crontab [-u user] -r

 

#编辑contab

crontab [-u user] -e