Alerting

How to set cron job to run last Thursday of every month at 2:00 AM

chandra61446
New Member

How to set cron job to run last Thursday of every month at 2:00 AM

Tags (1)
0 Karma

inventsekar
SplunkTrust
SplunkTrust
* * * * *, correspond to minute hour day month day-of-week.

0 2 25-31 * 4

- 2am, on the thursday between dates 25 to 31,

0 Karma

jkat54
SplunkTrust
SplunkTrust

0 2 25-31 * 4

Can be read as: @ 2am, On days 25-31, every month, on Thursday

Hopefully there wont be more than one Thursday between 25th and 31st... call me if so 😉

It just so happens that the current month is a great example of how the 25th might be the last Thursday.

However, this will probably fail on some months with less than 31 days. So you really need one alert for each month:

0 2 25-31 1 4 = Jan
0 2 22-28 2 4 = Feb (will not work on all leap years)
0 2 25-31 3 4 = Mar
0 2 24-30 4 4 = Apr
0 2 25-31 5 4 = May
0 2 24-30 6 4 = Jun
0 2 25-31 7 4 = Jul
0 2 25-31 8 4 = Aug
0 2 24-30 9 4 = Sep
0 2 25-31 10 4 = Oct
0 2 24-30 11 4 = Nov
0 2 25-31 12 4 = Dec

Which simplifies to this:
0 2 25-31 1,3,5,7,8,10.12 4 = Jan, Mar, May, Jul, Aug, Oct, Dec
0 2 22-28 2 4 = Feb (will not work on all leap years)
0 2 24-30 4,6,9,11 11 4 = Apr, Jun, Sep, Nov

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

I believe this is not quite correct, as it will run on days 25-31 AND on Thursdays. There is no way to do that easily that I know of.

0 Karma
Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...