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

29 thoughts on “crontab 的格式备忘”

  1. [Comment ID #13177 Will Be Quoted Here]

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

  2. [Comment ID #18849 Will Be Quoted Here]

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

  3. # 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
    ~

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

  4. 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.

  5. 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

  6. 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.

  7. 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!

  8. 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!

  9. 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!

  10. 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.

  11. 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!

  12. 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!

  13. 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!

  14. 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

  15. 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!

  16. You really make it seem so easy with your presentation but
    I find this topic to be actually something that I think I would never understand.
    It seems too complex and very broad for me. I’m looking forward for your next post, I will try to get the hang
    of it!

  17. Pingback: Weselne
  18. I’m extremely pleased to uncover this great site. I need
    to to thank you for your time just for this wonderful
    read!! I definitely really liked every bit of it and I have you book-marked to check out new stuff on your website.

  19. Having read this I believed it was very informative.
    I appreciate you finding the time and energy to put this information together.

    I once again find myself spending a significant amount
    of time both reading and posting comments. But so what, it was still
    worthwhile!

  20. Its like you read my mind! You seem to know so much about
    this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message
    home a little bit, but other than that, this is great blog.
    A great read. I’ll certainly be back.

  21. Undeniably believe that which you said. Your favorite justification appeared to
    be on the internet the easiest thing to be aware of. I say to you, I certainly get irked while people think about
    worries that they just don’t know about. You managed to hit
    the nail upon the top as well as defined out the
    whole thing without having side effect , people
    can take a signal. Will probably be back to get more.
    Thanks

  22. Howdy! I could have sworn I’ve been to this web
    site before but after going through some of the articles I realized it’s new to me.
    Nonetheless, I’m definitely happy I found it and I’ll be bookmarking it and checking back often!

  23. Pingback: sex xvideos
  24. Hi there would you mind stating which blog platform you’re working with?
    I’m looking to start my own blog in the near future but I’m having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different then most blogs
    and I’m looking for something unique.
    P.S Sorry for being off-topic but I had to ask!

  25. We stumbled over here coming from a different page and thought I may as well check things out.
    I like what I see so i am just following you.
    Look forward to checking out your web page repeatedly.

  26. Hey there I am so glad I found your web site, I really
    found you by accident, while I was browsing on Bing for something else, Regardless
    I am here now and would just like to say thanks a lot
    for a fantastic post and a all round exciting blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have book-marked it and also added
    in your RSS feeds, so when I have time I will be back to read a
    great deal more, Please do keep up the superb job.

  27. I think that everything published made a bunch of sense.
    However, think about this, what if you were to create a awesome post title?
    I mean, I don’t want to tell you how to run your blog, but what
    if you added a title that makes people want more?
    I mean crontab 的格式备忘 | 李俊麟的平凡生活 is
    kinda plain. You ought to glance at Yahoo’s front page and
    note how they write post headlines to get viewers to click.
    You might add a related video or a related picture or two to get people interested about what
    you’ve written. In my opinion, it would make your blog a little bit more interesting.

  28. Just desire to say your article is as astonishing. The clarity to your post is simply spectacular and that i can think you’re
    a professional in this subject. Well together with your permission let me to clutch your RSS feed to stay updated with coming near near post.

    Thanks a million and please carry on the gratifying work.

  29. Hey I am so grateful I found your site, I really found you
    by mistake, while I was looking on Google for something else, Nonetheless I am here now and would
    just like to say kudos for a tremendous post and a all round entertaining blog (I also love the theme/design), I don’t have
    time to read it all at the minute but I have book-marked it and also added in your RSS
    feeds, so when I have time I will be back to read a
    lot more, Please do keep up the awesome work.

  30. Pingback: Melanie Bowen

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