unix crontab and longest interval

simple brain teaser:

given standard unix crontab what is the longest possible interval between calls to the same program?

for example:

15 */2 * * * /bin/echo x

has interval 2 hours.

what is the longest possible? and how to make it?

10 thoughts on “unix crontab and longest interval”

  1. if i’m right, this is the correct answer:

    perl -MMIME::Base64 -le ‘print decode_base64″MjggeWVhcnMuIGNyb246IDAgMCAyOSAyIDI=”‘

    run this, it will print answer – i “coded” it not to spoil teaser for others.

  2. I don’t understand
    Why you place “2” on year column?
    What it gives you?

  3. I would guess something like this:
    python -c ‘import base64; print base64.decodestring(“MCAwIDI5IDIgNCAtPiBnaXZlcyAyOCB5ZWFycywgbmV4dDogMjAzNg==\n”)’

    On the other hand remember about leap seconds! Crontab doesn’t support second precision, but if it did: 61st second, monday, 30th june

    I think nobody can tell me whan it would happen 🙂

  4. python -c “print ‘IyEvdXNyL2Jpbi9weXRob24KCmZyb20gZGF0ZXRpbWUgaW1wb3J0IGRhdGV0aW1lCgptYXhfeWVh\ncnMgPSAwCnByZXZfdHVlMl8yOSA9IHN0YXJ0ID0gMTk4NAoKZm9yIHllYXIgaW4gcmFuZ2UoIHN0\nYXJ0LCAzMDAwICk6Cgl0cnk6CgkJaWYgZGF0ZXRpbWUoIHllYXIsIDIsIDI5ICkud2Vla2RheSgp\nID09IDI6CgkJCXllYXJzID0geWVhciAtIHByZXZfdHVlMl8yOQoJCQlpZiB5ZWFycyA+IG1heF95\nZWFyczoKCQkJCW1heF95ZWFycyA9IHllYXJzCgkJCXByZXZfdHVlMl8yOSA9IHllYXIKCWV4Y2Vw\ndCBWYWx1ZUVycm9yOgoJCXBhc3MKCnByaW50IG1heF95ZWFycwoK’.decode(‘base64’)” | python

  5. I see you liked python coded answers 🙂
    Now I know that last “column” is day of week, not a year
    my mistake 😐
    It changes a lot 😉

  6. @Evolic:
    tuesday. cron means: every 29th of february, which is tuesday (i could use any day, but tuesday looks nice)

    @majek:
    great – actually – it’s practically the same solution – it shouldn’t matter whether there is “2”, “4”or anything else on last position.

  7. apparently i was mistaken, and my solution for 28year long period is not valid (this also applies for majek solution).

    reason is in manual to crontab:

    Note: The day of a command’s execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren’t *), the command will be run when either field matches the current time. For example,

    “30 4 1,15 * 5” would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

    so, actually cezio is right – the longest period would be on 0 0 29 2 *. 🙂

Comments are closed.