FAQ
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Matt Zagrabelny at Nov 5, 2012 at 1:15 pm

    On Mon, Nov 5, 2012 at 4:23 AM, Alexander Holte-Davidsen wrote:
    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
    Hmmm. Should that be:

    00 18 18 12 *

    ?

    20 is an invalid month.
    Has anyone done anything similar and are willing to give me some input on
    how to solve this?
    Instead of using the wildcard ('*') month, could you (simply) specify
    the months?

    0 18 20 1 *
    0 18 18 2 *
    0 18 20 3 *
    0 18 18 4 *
    0 18 20 5 *
    0 18 18 6 *
    0 18 20 7 *
    0 18 18 8 *
    0 18 20 9 *
    0 18 18 10 *
    0 18 20 11 *
    0 18 18 12 *

    -mz

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Dan White at Nov 5, 2012 at 1:48 pm
    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.davidsen@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+unsubscribe@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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Alexander Holte-Davidsen at Nov 5, 2012 at 2:23 pm
    Hi!

    Thanks for the feedback! Unfortunately both suggestions gives me to little
    freedom, so I ended up using the chronic gem for ruby. I can give a small
    example of what I have done. Please not that this is extremely early in the
    development:

    class test {
    $weeknumber = '3'
    $weekday = 'Tuesday'
    $hour = '22'
    $minute = '00'
    $monthday = template('test/date.erb')

    if ( $monthday =~ /^UNDEF/ ) {
    notify {'Monthday is wrong': }
    }
    else {
    cron{'Testing':
    ensure => present,
    hour => "$hour",
    minute => "$minute",
    monthday => "$monthday",
    command => 'echo hello',
    }
    }
    }

    date.rb:
    <%=
    require 'time'
    require 'chronic'

    time = Time.new
    @month = time.strftime("%B").downcase.chomp
    @week = weeknumber.downcase.chomp
    @weekday = weekday.downcase.chomp

    date = Chronic.parse("#{@week}rd #{@weekday} this #{@month}").to_a
    if date[3].nil?
    day = 'UNDEF'.chomp
    else
    day = date[3]
    end
    %>


    All I have to do now is to set $weeknumber and $weekday and the rest is
    calculated by date.erb... Maybe not the pretties code out there, but as I
    said - extremely early in the development.

    Matt, of course it was wrong, thanks for pointing that out. The month
    should have been 12, not 20. Darn typos.

    Regards,
    Alexander

    On Mon, Nov 5, 2012 at 2:48 PM, Dan White wrote:

    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.davidsen@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+unsubscribe@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+unsubscribe@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+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedNov 5, '12 at 10:23a
activeNov 5, '12 at 2:23p
posts4
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase