In this chapter we will add some 'date' macros to improve our script.
Please see the
sample scripts section on macros and the sample scripts shipped with WinCron for more examples.
# Schedule job to run every day except Saturday and Sunday,
# between the hours of 8:00 AM and 5:00 PM
{
# Name our job
-name my job
#Create a log file where the name of the log encodes the date/time
# This is nice because the logfile will be different each time the computer is booted
# The format of the file name is:
# %m% Month as decimal number (01-12)
# %d% Day of month as decimal number (01-31)
# %H% Hour in 24-hour format (00-23)
# %M% Minute as decimal number (00-59)
-action -logfile C:\temp\logs\%m%%d%%H%%M%.txt# Start now and increment the day field.
# This will cause the job to fire NOW, and at the same time tomorrow
-start -inc 1 0 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!
It's Monday! (or whatever the current weekday name is) # (Or do whatever real work you wish)
-action -print "Hello World!"
It's %A%!}
Okay, lets rewrite our script to use variables to store some values
# Schedule job to run every day except Saturday and Sunday,
# between the hours of 8:00 AM and 5:00 PM
{
# Name our job
-name my job
#Create a log file where the name of the log encodes the date/time
# This is nice because the logfile will be different each time the computer is booted
# The format of the file name is:
# %m% Month as decimal number (01-12)
# %d% Day of month as decimal number (01-31)
# %H% Hour in 24-hour format (00-23)
# %M% Minute as decimal number (00-59)
-action -set logname=C:\temp\logs\%m%%d%%H%%M%.txt
# create the logfile with the name stored in logname
-action -logfile %logname%# Start now and increment the day field.
# This will cause the job to fire NOW, and at the same time tomorrow
-start -inc 1 0 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.
# Store Hello World! It's Monday! (or whatever the current weekday name is)
# in the variable
text-action -set text="Hello World! It's %A%!"
# Print the contents of text
-action -print %text%}