In the last chapter we added
day skipping to our job.
Our job now prints "Hello World!" every day, except on Saturday and Sunday.
Many jobs though, should only be run between certain hours of the day.
For instance, 8:00 AM to 5:00 PM (bankers hours.)
A couple of new directives allow excluding blocks of time within a day.
-suspend [ date / time specification ]
-resume [ date / time specification ]
For a complete explanation of the arguments to the suspend and resume directives, see the documentation:
-suspend Let us now expand our job to only run between 8:00 AM and 5:00 PM
# Schedule job to run each hour, between the 8:00 AM and 5:00 PM,
# except Saturday and Sunday,
{
# Name our job
-name my job
# Start now and increment the hour field.
# This will cause the job to fire each hour starting now
-start -inc 0 1 0 0
# Skip Saturday and Sunday
-skip -week 7,1
# Suspend all processing before 8:00 AM
# (Start suspending at 12:00 AM and resume at 8:00 AM)
-suspend -time 12:00:00 AM
-resume -time 8:00:00 AM
# Suspend all processing after 5:00 PM
# This suspension will run until the 24 hour clock
# rolls-over at 12:00 AM
-suspend -time 5:00:00 PM
# if it is between 8am and 5pm, do our job.
# Print Hello World!
# (Or do whatever real work you wish)
-action -print "Hello World!"
}
Now because the suspend and resume directives use a reference counter, it is easy to have multiple exclusion blocks per a job, as well as nested exclusion blocks. (If you don’t know what I’m talking about, it’s ok, you probably don’t need this advanced functionality anyway.)