Step 8: Automating HWemail

Once people subscribe to receive their daily forecasts you will need to automate the emailhw2.cgi script to run once a day and send out the forecasts.  If you are using unix and have the ability to set cron jobs then it is fairly easy to automate the emailhw2.cgi.  If you are using an NT server then contact your provider to see if they will allow you to automate scripts if so they will need to set up the automation.   Otherwise your only options would be to browse to the emailhw2.cgi script once a day to have it send out the forecasts.

To set up a cron job to automate the emailhw2.cgi you will need to create a text file with the cron job to run.  FOr the example here, the file will be named "my.crontab.txt".

In the first line of the cron job you will add the following line, though changing the perl path and path to the script to match those on your server:

22 6 * * * /path/to/perl /path/to/the/emailhw2.cgi

The above would run the emailhw2.cgi everyday at 6:22 am.

Each entry in a crontab file consists of six fields, specified in the following order:

The fields are separated by spaces or tabs. The first five are integer patterns and the sixth is the command to be executed. The following table briefly describes each of the fields.

Field Value Description
minute 0-59 The exact minute that the command sequence executes.
hour 0-23 The hour of the day that the command sequence executes.
day 1-31 The day of the month that the command sequence executes.
month 1-12 The month of the year that the command sequence executes.
weekday 0-6 The day of the week that the command sequence executes. Sunday=0, Monday = 1, Tuesday = 2, and so forth.
command Special The complete command sequence variable that is to be executed.

Each of the patterns from the first five fields may either be an asterisk (*) (meaning all legal values) or a list of elements separated by commas.

Now save the fiel withthe name my.crontab.txt.  Upload the file to your server.   Then telnet in to your account and goto the directory where you stored the my.crontabl.txt file to.  Once there you can install the cron job by using the following command from telnet:

crontab my.crontab.txt

This should set the corn job.  To see a list of all cron jobs set you can use:

crontab -l  (thats a lower case L)

and to remove your cronjobs simply enter:

crontab -r

Once this is done your emailhw2.cgi script should run per the schedule you set.