You cannot directly set up a cron job to run on the N-th (day-of-the-week).

>From the manpage crontab(5):
 
Note:  The  day of a command’s execution can be specified by two fields — day 
of month, and day of week.  If both fields are restricted (ie, aren’t *), 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.
--------------

To get a script that runs on the N-th Tuesday, I did this:

today=`date +%u`

if [ $today -eq $1 ]
then
....
fi

Then, I call the script from cron like this:
# Run patch script on second Tuesday of every month
05      02      8-14     *       *       root    
/usr/local/scripts/cronScript.sh 2

---------------------
So, the script will run once a day from the 8th thru the 14th and only execute 
the guts of the conditional on Tuesday

Adjust the day-of-the-month field accordingly to get the week you want. 


“Sometimes I think the surest sign that intelligent life exists elsewhere in 
the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)

----- Original Message -----
From: "Alexander Holte-Davidsen" <alexander.david...@gmail.com>
To: puppet-users@googlegroups.com
Sent: Monday, November 5, 2012 5:23:24 AM
Subject: [Puppet Users] Defining dynamic cron jobs

Hi all, 


I have a application that I schedule via cron. This is a application that runs 
once a week, either on Tuesday or Thursday. The scheduling is now done via 
Puppet. 


I now see that I need to redefine this, on some nodes the application should 
for example only run the 3. Tuesday each month, not each Tuesday. 
I want to do the scheduling using puppet and parameterized classes. For example 
I want to be able to define: 


foo {'Tuesday': 
week => '3', 
hour => '18', 
minute => '00', 
} 


This should generate a cron job ( that changes every month). For November it 
should look like this: 
00 18 20 11 * /usr/bin/foo 


Next month the crontab entry should be changed to: 
00 18 18 20 * /usr/bin/foo 


Has anyone done anything similar and are willing to give me some input on how 
to solve this? 


/ Alexander 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group. 
To post to this group, send email to puppet-users@googlegroups.com. 
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com. 
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en. 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to