www.delorie.com/gnu/docs/cfengine/cfengine-Tutorial_64.html   search  
Buy GNU books!

GNU cfengine

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Building flexible time classes

Each time cfagent is run, it reads the system clock and defines the following classes based on the time and date:

The current year, e.g. `Yr1997', `Yr2001'. This class is probably not useful very often, but it might help you to turn on the new-year lights, or shine up your systems for the new millenium!

The current month can be used for defining very long term variations in the system configuration, e.g. `January', `February'. These classes could be used to determine when students have their summer vacation, for instance, in order to perform extra tidying, or to specially maintain some administrative policy for the duration of a conference.

The day of the week may be used as a class, e.g. `Monday', `Sunday'.

A day in the month (date) may be used to single out by date, e.g. the first day of each month defines `Day1', the 21st `Day21' etc.

An hour of the day, in 24-hour clock notation: `Hr00'...`Hr23'.

The precise minute at which cfagent was started: `Min0' ... `Min59'. This is probably not useful alone, but these values may be combined to define arbitrary intervals of time.

The five-minute interval in the hour at which cfagent was executed, in the form `Min0_5', `Min5_10' .. `Min55_0'.

Time classes based on the precise minute at which cfagent started are unlikely to be useful, since it is improbable that you will want to ask cron to run cfagent every single minute of every day: there would be no time for anything to complete before it was started again. Moreover, many things could conspire to delay the precise time at which cfagent were started. The real purpose in being able to detect the precise start time is to define composite classes which refer to arbitrary intervals of time. To do this, we use the group or classes action to create an alias for a group of time values. Here are some creative examples:

classes:  # synonym groups:

  LunchAndTeaBreaks = ( Hr12 Hr10 Hr15 )

  NightShift        = ( Hr22 Hr23 Hr00 Hr01 Hr02 Hr03 Hr04 Hr05 Hr06 )

  ConferenceDays    = ( Day26 Day27 Day29 Day30 )

  QuarterHours      = ( Min00 Min15 Min30 Min45 )

  TimeSlices        = ( Min01 Min02 Min03 Min33 Min34 Min35)

In these examples, the left hand sides of the assignments are effectively the ORed result of the right hand side. This if any classes in the parentheses are defined, the left hand side class will become defined. This provides a flexible and readable way of specifying intervals of time within a program, without having to use `|' and `.' operators everywhere.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003