zoukankan      html  css  js  c++  java
  • linux下定时执行任务

    crontab的用法
    语法:crontab[-u username]|-l|-r|-e|-v
    -u:指定crontab job的用户
    -l:列出当前crontab的job
    -e:使用$EDITOR编辑crontab job
    -v:列出当前crontab job的状态,有的shell可能不支持-v
    crontab file填写格式:
    每一行对应一个cron job
    每一行分为六个部分,每一部分用空格隔开,同一个部分用逗号隔开
    minute  hour  day_of_month  month  weekday  command
    前五个域中使用*,则表示所有的时间点
    minute:0-59
    hour:0-23,0代表零点
    day_of_month:1-31
    month:1-12
    weekday:0-6,0代表星期天,1-6代表星期一到星期六
    command:需要执行的脚本或者命令
    $ cat test_cron.sh
    #!/bin/sh      
    #将系统时间输出到文件time.txt                                                                                                              
    echo `date`>>time.txt
    #查看当前的cronjob,系统提示没用用户habao的cronjob
    $ crontab -l
    no crontab for habao
    #添加cronjob
    $ crontab –e
    #没隔一分钟执行一次
    #显示当前系统时间#写在crontab文件中可方便查看定时作业的用途
    * * * * * /home/habao/test_cron.sh
    #再查看当前cronjob
    $ crontab -l
    # DO NOT EDIT THIS FILE - edit the master and reinstall.
    # (/tmp/crontab.3285 installed on Thu Sep 22 16:28:40 2011)
    # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
    #显示当前系统时间
    * * * * * /home/habao/test_cron.sh
    #查看输出文件time.txt
    $ cat time.txt
    Thu Sep 22 16:33:00 CST 2011
    Thu Sep 22 16:34:00 CST 2011
    Thu Sep 22 16:35:00 CST 2011
    Thu Sep 22 16:36:00 CST 2011
    Thu Sep 22 16:37:00 CST 2011
    Thu Sep 22 16:38:00 CST 2011
    Thu Sep 22 16:39:00 CST 2011
    若要修改当前cronjob则crontab –e
    若要删除当前cronjob则crontab –r

  • 相关阅读:
    easyUI中textbox或number的数值大小校验
    个人附加作业
    个人最终总结
    结对编程————电梯调度
    visual studio 2013的使用和单元测试
    第三次作业(二)
    团队作业之个人总结篇
    结队编程之总结篇
    电梯调度系统(界面由C图形库编绘)
    软件工程作业单词统计
  • 原文地址:https://www.cnblogs.com/zlxbk/p/7120779.html
Copyright © 2011-2022 走看看