Cron Job to run every 6 hours Mon to Fri
Asked by Mario Coluzzi:

Hello,

Anyone can help me in how to create a Cron Job to run an automation exmple: every 6 hours at 10:00 AM from Monday to Friday

This article is not clear in the matter not helpful in how to achieve that: <https://support.atlassian.com/jira-software-cloud/docs/manage-filters/>

Cheers


Answers:
author: Mario Coluzzi
body: Hi [@Manoj Gangwar](/t5/user/viewprofilepage/user-id/4484987) I did try something similar to your expression  
**0 10/6 \* ? \* MON-FRI** but I am unsure whether this works based on <https://support.atlassian.com/jira-software-cloud/docs/manage-filters/>

Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011) every 6 hours like a normal Cron Job would do: **0 \*/6 \* \* Mon-Fri** see [https://crontab.guru/#0_\*/6_\*_\*_Mon-Fri](https://crontab.guru/#0_*/6_*_*_Mon-Fri)

You option to use ELSE IF is a nice solution but TBH I should not go through the ordeal in creating an automation to automate the Cron Jobs. My automations are enough complex, although your option is a feasible option should I not find a solution


author: Manoj Gangwar
body: You may test the below corn expression.

0 10/6 \* ? \* MON-FRI

comments: author: Mario Coluzzi
body: Hi [@Manoj Gangwar](/t5/user/viewprofilepage/user-id/4484987)

That expressions runs the automation every 6 minutes. Tested it


author: Trudy Claspill
body: Hello [@Mario Coluzzi](/t5/user/viewprofilepage/user-id/4844127)

Note that I have not tested this solution as that would require the passage of days of time.

I recommend you use a Schedule trigger like this:

![schedule-trigger.png](https://community.atlassian.com/t5/image/serverpage/image-id/344957iED84C2A6509D42EC/image-size/large?v=v2&px=999 "schedule-trigger.png")

That will start the rule running at 10 am (Los Angeles time) on Monday. The lower portion will run the rule every 6 hours.

You then need to add a condition to check the current time when the rule is running to see if it is during the time you don't want it to run. You didn't specify the latest time on Friday when the rule could run, but running every six hours means that it could run at 4 am, 10 am, 4 pm, and 10 pm, So let us say that the latest run can be the 10 pm run.

You'll need to use an IF-ELSE block so that you can apply multiple conditions to see if it is in the black out period and proceed with the rest of your rule if it is not.

In the first IF block you will check if the current day is Saturday or Sunday. If it is you don't want to run the rule.

![IF-Sat.png](https://community.atlassian.com/t5/image/serverpage/image-id/344960i32194BBCBA8A45E7/image-size/large?v=v2&px=999 "IF-Sat.png")

![if-sun.png](https://community.atlassian.com/t5/image/serverpage/image-id/344958i3F0528EA968E8AAE/image-size/large?v=v2&px=999 "if-sun.png")

The smart value to extract the day of week from the current time, with a conversion to relevant timezone, is:

{{now.convertToTimeZone("America/Los_Angeles").format("EEE")}}

In this case you don't want to run the main actions of the rule, but you must run some action. So add a Log action to log a message of your choice to the rule execution audit log.

Insert an Else-If to check for the next blackout condition; is it Monday and before 10 am.

![IF-MON-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/344961i6C4FCCE78087FC1A/image-size/large?v=v2&px=999 "IF-MON-1.png")

![IF-MON-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/344962i8A027CC6AF7E5574/image-size/large?v=v2&px=999 "IF-MON-2.png")

The smart value to get the current hour of the day, with the conversion to the relevant timezone, is:

{{now.convertToTimeZone("America/Los_Angeles").format("k")}}

Again, since this is within the blackout you don't want to execute the main actions of your rule but you must execute some action. So add another Log action..

Lastly add the last Else after which you add the actions you want to execute for your automation.

![rule-1.png](https://community.atlassian.com/t5/image/serverpage/image-id/344966i7DAC3BBB9CAF0A29/image-size/large?v=v2&px=999 "rule-1.png")

![rule-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/344967iAAD409333E5ADB63/image-size/large?v=v2&px=999 "rule-2.png")

comments: author: Trudy Claspill
body: [@Mario Coluzzi](/t5/user/viewprofilepage/user-id/4844127)

Can you clarify what you mean by your timing statement ?

Every 6 hours at 10 am Monday through Friday

Does that mean starting at 10 am each day a and ending at midnight each day, so that there would be 3 runs each day?

Or does that mean starting at 10 am on Monday and running every 6 hours continuously until a specific time on Friday?

My answer applies to the latter.


author: Trudy Claspill
body: > Hi [@Trudy Claspill](https://community.atlassian.com/t5/user/viewprofilepage/user-id/3569011) every 6 hours like a normal Cron Job would do: **0 \*/6 \* \* Mon-Fri** see [https://crontab.guru/#0_\*/6_\*_\*_Mon-Fri](https://crontab.guru/#0_*/6_*_*_Mon-Fri)
>
> You option to use ELSE IF is a nice solution but TBH I should not go through the ordeal in creating an automation to automate the Cron Jobs. My automations are enough complex, although your option is a feasible option should I not find a solution

Hello [@Mario Coluzzi](/t5/user/viewprofilepage/user-id/4844127)

In your post you mentioned that you wanted the cron job to start at 10 am on Monday. That is the point I am trying to clarify.

Do you want the job to start at 10 am Monday and then run every 6 hours continuously through Friday?

Or do you want the first run of the job to be at 10 am each day, Monday through Friday?

\*/6 for the Hours and MON-FRI for the days of week would start at 00:00 on Monday and run every six hour through 24:00 on Friday.

If you use 10/6 and MON-FRI then the job will start at 10:00 am each day and run every six hours until 23:00 that day.  

If either of the two options above matches your needs then you don't need the If-Else blocks I described.

If you need something that starts at 10 am on Monday and then runs continuously every 6 hours through Friday then your options are:

1. The If-Else structure I suggested.
2. Multiple rules with different cron settings to match the every 6-hour pattern you want:  
   Monday: 10 am, 4 pm, 10 pm  
   Tuesday-Friday: 4 am, 10 am, 4 pm, 10 pm  

   10/6 MON  
   4/6 TUE-FRI  


author: Mario Coluzzi
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

I did put as [@Manoj Gangwar](/t5/user/viewprofilepage/user-id/4484987) said: **0 10/6 \* ? \* MON-FRI** the automation runs every 6 minutes. I did test it. See logs timestamp dump below

It does not matter if the automation start running at 10:00 or at 15:20 or at 23:11 It has to run every 6 hours between weekdays of Mon to Fri.

If it can start at 00:01 even better

03/09/24, 10:22:29 pm

03/09/24, 10:17:56 pm

03/09/24, 10:14:01 pm

03/09/24, 10:00:31 pm

03/09/24, 09:54:29 pm

03/09/24, 09:48:25 pm

03/09/24, 09:42:44 pm

03/09/24, 09:36:29 pm

03/09/24, 09:28:54 pm

03/09/24, 09:22:55 pm

03/09/24, 09:17:17 pm

03/09/24, 09:11:15 pm


author: Trudy Claspill
body: The cron statement needs to include a Seconds element in the first position.

\* 1 0/6 \* \* MON-FRI

Any Second, minute 1 of the hour, starting with hour 0 then every 6 hours, any day of the month, any month of the year, on the days of the week Monday through Friday.

Should work, but I haven't had a chance to test it.


author: Mario Coluzzi
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

**It does work!** I put in place and it does the job.

Although Jira complains on wrong formatting, therefore the correct one is:

**\* 1 0/6 ? \* MON-FRI**

A bit tricky one but in the end we crack it

Thank you.

M

*05/09/24, 12:04:28 am - Scheduled for - NO ACTIONS PERFORMED*

*04/09/24, 06:04:07 pm - Scheduled for - SUCCESS*


author: Trudy Claspill
body: Wonderful!

If our responses were helpful please consider clicking on the Accept Answer buttons to mark your Question as Solved.


Tags: cloud

jira-service-management

jira-service-management-cloud