Cron expression: every two Fridays

Hi all,

I need a cron expression to schedule a trigger every two Fridays.
I have tried this one “0 0 * * Fri [ $(expr $(date +%W) % 2) -eq 1 ] && /path/to/command”, but I am getting Invalid cron expression.

Could you help me, please?

Thanks.

@Isabel_Lopez

"0 0 * * Fri#1,Fri#3"

This expression will schedule the trigger to run at midnight (0:00) on the first and third Fridays of each month. You can adjust the numbers after the # to select different occurrences within a month.

Hi @Isabel_Lopez

0 0 * * 5 [ $(expr $(date +\%W) \% 2) -eq 1 ] && /path/to/command

In this expression:

  • 0 0 specifies midnight as the time of day.
  • * * allows the command to run every day and every month.
  • 5 represents Friday as the day of the week (Sunday is 0, Monday is 1, and so on).
  • [ $(expr $(date +\%W) \% 2) -eq 1 ] is your condition for running the command every two Fridays.

Hope it helps!!

Hi @Isabel_Lopez

Try this:
0 0 * * 5 [ $((($(date +\%U) \% 2)) -eq 1 ] && your_command_here

0 0 * * 5 schedules the task to run every Friday at midnight.
[ $((($(date +%U) % 2)) -eq 1 ] is to run the command only if the current week number is odd

we assume the cron is intended to be used it within Orchestrator trigger configuration, right?

A month can also have more then 4 weeks
grafik

so a static first, third friday will not match

A biweekly interval is in general against the nature of cron
Working with a dynamic part within the cron is not supported when specifying the cron for ORC trigger setting

Working with a dynamic part within the cron

in other words: $(date… will not work / be accepted

Yes, you all right. It’s an orchestrator trigger.

Hi @Isabel_Lopez

If you want to trigger the bot for second and forth Friday of a month, use the below expression

Cron Expression:
0 0 * * 5#2,5#4

Hope it helps!!

@Isabel_Lopez

You cannot directly do this only using orchestrator

You have to use a logic in your code as well to run as expected

One thing you can do is …

  1. Schedule bot on every friday
  2. Now create a asset names lstrun and initially give the first rundate as input
  3. Now in the initialize state use get asset and get last rundate…and check the fifference between today and lastrundate using datediff function…
  4. If the difference is 14 then run the process or if difference is greater than 8 …then run process and set the asset with todays date
  5. Else it is not the alternate friday so end the process in initialize only

Hope this helps

Cheers

That’s work great. Thanks a lot for your response.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.