Bug 1571446 - Cron jobs for every second sunday does not work.
Summary: Cron jobs for every second sunday does not work.
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Remote Execution
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-04-24 20:03 UTC by Shivdutt Bharadwaj
Modified: 2018-04-26 15:09 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-04-25 08:10:09 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Shivdutt Bharadwaj 2018-04-24 20:03:02 UTC
Description of problem: Cron jobs for every second Sunday does not work. It shows 22nd as next occurrence.

Cron line used - 0 4 8-14 * 0, it should run only only between 8-14. But next run shows on 22nd of that month. 


Version-Release number of selected component (if applicable):
Satellite 6.2.x
Satellite 6.3.x

How reproducible: Always


Steps to Reproduce:
1. Monitor > Jobs > create a new job with cronline   0 4 8-14 * 0
2. The recurring logic shows next occurrence on 22nd.
3. 

Actual results: Job running on 22nd


Expected results: Job should run only on second sunday


Additional info:

Comment 1 Adam Ruzicka 2018-04-25 08:10:09 UTC
From man 5 crontab:

"""
Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'.  If both fields are  restricted (i.e., do not contain the "*" character), 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.
"""

According to this the cronline you provided would run a job at 4AM every day from 8th to 14th and on every Sunday.

Reading the customer case it seems they were reading upstream documentation where this case is described with an error and I'll fix it there. The only way they could do it would be to have the job run on every day from 8th to 14th and start the script with a check for the day of the week and exiting early in case the day of the week is not Sunday, which roughly translates to what they were doing on RHEL with 0 4 8-14 * * [[ date +%a == "Sun"  ]] && echo "some task".

The manpage piece leads me to believe our implementation adheres to the de-facto standard and we shouldn't deviate from it. I'll close this bug now, please feel free to reopen it if you feel strongly about it.

Comment 2 Shivdutt Bharadwaj 2018-04-26 14:02:01 UTC
As mentioned, 0 4 8-14 * * [[ date +%a == "Sun"  ]] && echo "some task" works for rhel but not on satellite via cronline.

Is there any way to execute job on second Sun of every month?

Comment 3 Adam Ruzicka 2018-04-26 15:09:38 UTC
0 4 8-14 * * [[ date +%a == "Sun"  ]] can be roughly translated to "on days matching 0 4 8-14 * *" run "[[date +%a == 'Sun' ]] && somescript".

You can do exactly the same in satellite, you specify a job with "0 4 8-14 * *" cronline and prefix the executed script with

if [[ date %a == 'Sun' ]]; then
  # The actual script goes here
fi

So on every day from the 8th to the 14th the job will run against the host and check if it is the right day, in which case it will do what is needed, otherwise it will skip it and exit.

In other words, you have to split the cronline you would specify on RHEL into two parts, into the time specification (the first five fields) and the command (the rest).


Note You need to log in before you can comment on or make changes to this bug.