crontab 的格式备忘

经常用,但是经常忘记,基本的格式能记得,但是详细的或者复杂点的格式总会忘记或者拿不准,不知道是不是年纪大了记忆力下降,干脆整理出来今后方便查看。

基本格式 :
*  *  *  *  *  command
分 时 日 月 周 命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

crontab文件的一些例子:

30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启lighttpd 。

45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重启lighttpd 。

10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每周六、周日的1 : 10重启lighttpd 。

0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启lighttpd 。

0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重启lighttpd 。

* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小时重启lighttpd

* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11点到早上7点之间,每隔一小时重启lighttpd

0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4号与每周一到周三的11点重启lighttpd

0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一号的4点重启lighttpd

Category: Linux / BSD
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
29 Responses
  1. zhangzijian says:

    呵呵,为什么不把常用的,但记不住的东西打印出来,放在手边呢?其实也不是年龄大了,很多人都无法记住这些东西.

  2. Michael says:

    [Comment ID #13083 Will Be Quoted Here]

    嗯,言之有理,我之前就是整理了一些BSD系统各种应急处理方法,打印了放在笔记本包包里面,还真是用到了好几次。

  3. Javayou says:

    可是为什么要重启apache呢? 哈

    我习惯用的时候再来找,但是前提是知道有这么个东西

  4. Michael says:

    [Comment ID #13177 Will Be Quoted Here]

    哈哈,这个只是个例子而已了:)实际并不重启,我经常一个月也不用重启一次,现在服务器用的webServer是Nginx,不是Apache,你可以telnet后GET看看header,嘿嘿

  5. zhangzijian says:

    经常来你的blog看看.你是个挺有意思的人.如果能整理一套应急的方案,都可以奉献出来,给大家一块享用了。不过如果自己没有接触过,这些方案也就白白放在那里了.

  6. 南半球 says:

    good,最近我也在用,每天定时统计排行榜

  7. bssn says:

    这个是重启apache的?
    30 21 * * * /usr/local/etc/rc.d/lighttpd restart

    这不是重启lighttpd的吗?

    apache的我记得这样吧

    /sbin/service httpd restart

  8. Michael says:

    [Comment ID #18643 Will Be Quoted Here]

    哈哈,这个只是个书写的范例罢了,文章的主要目的不是为了记录这个,而是crontab的格式 🙂

  9. L0uiS says:

    0,1 * * * * /usr/L0uiS/Bishop/guard/AutoStartKFXGuard

    我这样写是每1分钟都执行一下这个(AutoStartKFXGuard)脚本吗??请回答!!!
    thx

  10. Michael says:

    [Comment ID #18849 Will Be Quoted Here]

    每小时的整点和每小时的第一分钟执行一次,不是每分钟,如果每分钟可以写成 * * * * * cmd 或者 */1 * * * * cmd 不过第二种方式在solaris下不生效,仅Linux下有效。

  11. L0uiS says:

    * * * * * cmd /usr/L0uiS/Bishop/guard/AutoStartKFXGuard

    是这样写吗??
    cmd是执行的意思???

  12. Michael says:

    对,cmd就是你要执行的命令

  13. L0uiS says:

    我能电话联系您吗??
    我非常着急!

  14. L0uiS says:

    # run-parts
    01 * * * * root run-parts /etc/cron.hourly
    02 4 * * * root run-parts /etc/cron.daily
    22 4 * * 0 root run-parts /etc/cron.weekly
    42 4 1 * * root run-parts /etc/cron.monthly
    #AutoStartKFXGuard
    * * * * * /usr/L0uiS/bishop/AutoStartKFXGuard
    ~

    这里面应该怎么写?????????谢谢你

  15. L0uiS says:

    你在吗????
    我想开机掉用AutoStartKFXGuard这个脚本
    该如何写呢??????

    老问题,还是没有成功!
    谢谢你的耐心回答。。。

  16. L0uiS says:

    你在吗????
    我想每分钟掉用AutoStartKFXGuard这个脚本
    该如何写呢??????

    老问题,还是没有成功!
    谢谢你的耐心回答。。。

  17. L0uiS says:

    不是开机,是每分钟。不好意思

  18. Michael says:

    执行下列命令:
    # crontab -e

    加入这样一行
    * * * * * /usr/L0uiS/bishop/AutoStartKFXGuard

    保存退出 (:wq)

    完成

  19. zhusupe says:

    不错,多谢。

  20. 布布 says:

    正在找cron的资料,谢谢

  21. air max says:

    Exclusive: Melissa Gorga and Kathy Wakile Will Not air max shoes Be Spending Thanksgiving With Teresa Giudice!

  22. sacoche louis vuitton Saskatchewan multiple sclerosis patients hoping to take part in a clinical trial of a controversial treatment may soon get a call from the ministry of health.

  23. air yeezy 2012 Air Canada flights were set to stop this week after the airline said it would lock out its pilots and the machinists union said it would strike in the midst of the key spring holiday season.

  24. many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!!!

  25. To set the tone, Grace relied on the wisecracking snappy patter — “she gives as good as she gets,” Pearce says — between Emilie and Pearce’s agent.

  26. http://www.lovemichaelkors.com/ michael kors handbags
    Nice post, good to know that this topic is being covered also in this web site. Excellently written article, if only all blogger offered the same level of content as you.

  27. Thank you for an additional fantastic blog. michael kors storesWhere else might one get that sort of information written in such a perfect way?michael kors outlet I actually have a presentation that i am presently working on, and that i are looking for such information instead!michael kors handbags

  28. I am extremely impressed with your writing skills and also with the design of your blog. michael kors factoryIs this a paid theme or did you edit it yourself? Either way keep up the great quality writing, it is rare to see a nice website such as this one these days!

  29. ptc sites says:

    It’s an awesome paragraph in favor of all the online viewers;
    they will get advantage from it I am sure.

  30. You should take part in a contest for one of the
    greatest sites on the internet. I most certainly
    will recommend this website!

  31. Pretty sectgion of content. I just stumbled upon your site
    and inn accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Anyway I will be subscribing to your augment
    and even I achievement you access consistently
    rapidly.

  32. ptc monitor says:

    Just want to say your article is as astounding. The clearness on your submit is
    simply excellent and that i could suppose you’re a professional on this
    subject. Fine together with your permission allow me to grab your
    RSS feed to keep up to date with drawing close post.
    Thank you 1,000,000 and please keep up the enjoyable work.

  33. Quality content is the important to be a focus
    for the visitors to pay a visit the web page, that’s what this web page is providing.

  34. minecraft says:

    I don’t know whether it’s just me or if everybody else experiencing issues with your website.

    It looks like some of the written text in your posts are running off the screen. Can someone else please
    comment and let me know if this is happening to them as well?
    This could be a issue with my browser because I’ve had this happen before.
    Appreciate it

  35. minecraft says:

    Very energetic blog, I liked that bit. Will there be a part 2?

  36. minecraft says:

    Just wish to say your article is as surprising.
    The clarity in your post is simply excellent and i could assume you are an expert
    on this subject. Fine with your permission allow me
    to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please carry on the rewarding work.

  37. minecraft says:

    Thanks for your marvelous posting! I truly enjoyed reading it, you
    happen to be a great author. I will make sure to bookmark your blog and definitely will come
    back from now on. I want to encourage you to ultimately continue your great writing, have a nice holiday weekend!

  38. minecraft says:

    My relatives every time say that I am killing
    my time here at web, except I know I am getting familiarity all the time by reading such pleasant articles.

  39. minecraft says:

    Good day! I could have sworn I’ve been to this website before but after going through
    a few of the posts I realized it’s new to me. Nonetheless, I’m certainly
    happy I stumbled upon it and I’ll be bookmarking it and checking back
    frequently!

  40. minecraft says:

    If some one desires expert view about blogging afterward i propose him/her
    to visit this webpage, Keep up the fastidious work.

  41. minecraft says:

    Currently it sounds like BlogEngine is the best blogging platform available right now.
    (from what I’ve read) Is that what you’re using on your blog?

  42. minecraft says:

    An interesting discussion is worth comment. I believe that you should write more about
    this subject, it may not be a taboo subject but typically people don’t
    speak about these topics. To the next! All the best!!

  43. minecraft says:

    Usually I do not learn article on blogs, but I would like
    to say that this write-up very forced me to take a look at and
    do so! Your writing taste has been amazed me. Thank you, very nice post.

  44. minecraft says:

    I really like your blog.. very nice colors & theme. Did
    you create this website yourself or did you hire someone to
    do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u got this
    from. thank you

  45. minecraft says:

    Woah! I’m really digging the template/theme of this blog.
    It’s simple, yet effective. A lot of times it’s very hard to get
    that “perfect balance” between user friendliness and appearance.
    I must say you’ve done a superb job with this.
    Also, the blog loads super quick for me on Safari. Outstanding Blog!

  46. minecraft says:

    bookmarked!!, I really like your site!

  47. minecraft says:

    An outstanding share! I’ve just forwarded this onto a coworker
    who was doing a little research on this. And he in fact ordered me
    lunch due to the fact that I found it for him…
    lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending some time to discuss this issue here on your
    site.

  48. minecraft says:

    I’m really enjoying the design and layout of your site.
    It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often.
    Did you hire out a designer to create your theme?
    Superb work!

  49. minecraft says:

    Thanks for sharing your thoughts about minecraft.
    Regards

  50. minecraft says:

    Hello there! This article could not be written any
    better! Going through this post reminds me of my previous roommate!
    He always kept talking about this. I’ll forward this article to him.
    Fairly certain he’s going to have a very good read. Thanks for sharing!

  51. I pay a visit day-to-day a few sites and blogs to read articles
    or reviews, however this website presents quality based posts.

  52. Do you have a spam problem on this blog; I also am a blogger, and I was wanting to know your situation; we have developed some nice methods and we are looking to trade strategies with other folks, be sure
    to shoot me an email if interested.

  53. You need to be a part of a contest for one of the most useful blogs online.
    I’m going to highly recommend this blog!

  54. If you want to grow your know-how only keep visiting this web page and be updated with the hottest news posted here.

  55. Keep in mind that the starting heap measurement
    may be the same for several at the beginning of the contest.

  56. First of all I would like to say superb blog!
    I had a quick question in which I’d like to ask if you do not mind.
    I was interested to find out how you center yourself and clear your mind prior to writing.
    I’ve had a difficult time clearing my mind in getting my thoughts out there.

    I do take pleasure in writing but it just seems like
    the first 10 to 15 minutes are usually lost simply just trying to
    figure out how to begin. Any recommendations or hints? Thanks!

  57. Hi it’s me, I am also visiting this website daily, this website is actually fastidious and
    the users are truly sharing pleasant thoughts.

  58. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and everything. However just imagine if you
    added some great images or video clips to give your posts more, “pop”!
    Your content is excellent but with images and video clips,
    this website could undeniably be one of the greatest in its niche.

    Superb blog!

  59. Hi there! This is kind of off topic but I need some guidance from an established blog.
    Is it hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to begin. Do you have any tips or
    suggestions? Many thanks

  60. Hi there it’s me, I am also visiting this web site regularly, this website is in fact
    good and the people are really sharing good thoughts.

  61. Sling TV says:

    I am regular visitor, how are you everybody? This post posted at
    this web page is genuinely pleasant.

  62. Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and everything.
    However imagine if you added some great graphics or videos to give your posts more,
    “pop”! Your content is excellent but with images and video clips, this website could definitely
    be one of the best in its niche. Fantastic blog!

  63. Thanks for your personal marvelous posting! I quite enjoyed
    reading it, you can be a great author.I will be sure to bookmark your
    blog and may come back someday. I want to encourage
    yourself to continue your great writing, have a nice afternoon!

  64. Heya! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing
    months of hard work due to no data backup. Do you have any methods to prevent
    hackers?

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image