Giter VIP home page Giter VIP logo

Comments (6)

Draxter avatar Draxter commented on June 16, 2024

I have also tried an alternative cron expression 0 0 ? * TUE#2

However gocrond returns a syntax error:

{"command":"/files/job_1.sh","crontab":"/etc/crontabs/job_1","level":"error","msg":"cronjob failed adding: failed to parse int from TUE#2: strconv.Atoi: parsing \"TUE#2\": invalid syntax","shell":"sh","spec":"0 0 ? * TUE#2","time":"2023-07-05T09:02:04+12:00","user":"root"}

from go-crond.

smlx avatar smlx commented on June 16, 2024

Looks like the 8-14 day of month range is ignored, and the job runs every Tuesday. I also double chcked the date and time on the container, and it's correct. Any ideas?

From crontab(5):

Commands are executed by cron(8) when the minute, hour, and month of year fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time.

So that means commands are executed if either of the third (day of month) or fifth (day of week) fields match.

In your case, the command will run at midnight every day between the 8th and 14th (inclusive) of every month, and on every Tuesday.

Edit: Sorry, forgot to mention you can achieve "the second Tuesday of every month" like this:

0 0 8-14 * * [ $(date +\%u) = 2 ] && /files/job_1.sh

from go-crond.

Draxter avatar Draxter commented on June 16, 2024

@smlx Sounds like you are right, and that first cron expression is incorrect.

For now I worked around it by using a ‘test’ command before running job_1. It checks whether its Tuesday and cron expression runs the job between 8th and 14th.

Expressions like ‘TUE#2’ still aren’t supported though, which are a part of a cron spec. Might be a useful feature to add.

from go-crond.

smlx avatar smlx commented on June 16, 2024

Expressions like ‘TUE#2’ still aren’t supported though, which are a part of a cron spec. Might be a useful feature to add.

That's Java's crontab-like syntax, and I've never seen it implemented elsewhere. It is not part of any specification I'm aware of - certainly not POSIX crontab.

from go-crond.

Draxter avatar Draxter commented on June 16, 2024

Fair enough, I stand corrected. I guess I will need to stick with the test workaround for unusual time intervals like “every second Tuesday”.

Edit: Thanks @smlx, I came up with something similar: test $(date +\%u) -eq 2 && /files/job_1.sh

Though even that is not ideal, as it counts as a failure on days other than Tuesday as far as gocrond is concerned, which triggers my alerting :(

from go-crond.

smlx avatar smlx commented on June 16, 2024

Though even that is not ideal, as it counts as a failure on days other than Tuesday as far as gocrond is concerned, which triggers my alerting :(

You can fix this using an if statement:

if [ $(date +\%u) = 2 ]; then /files/job_1.sh; fi

from go-crond.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.