|
Introduction
Firing events on a Web server is an easy task. Depending
upon what type of solution you are trying to provide and what type of event
you are trying to fire on a predetermined basis, you could use the Win2K
Scheduled Tasks, SQL Server Agent or the "at" command. However, all of these
tools require you to have your own dedicated Internet Information Server (IIS) or SQL Server on the Internet to play with, a privilege not shared by many. Since most (all that I could find) Microsoft-based Internet Service Providers (ISPs) do not allow you access to these tools, you need to get a little creative in order to get the same functionality as you would if you did have your own dedicated server.
Body
The first step in firing your event is to create an ASP that does whatever
you need it to do. In my case I needed it to pull a number of values from
a database, including an email address, and then send out dynamically
generated emails based on the user values. You can think of it as a script
that allows you to do target marketing.
Once your ASP is built and uploaded to your ISP, you should be able to call
it from a Web browser and make sure it performs properly. The next step is to create the functionality that makes the ASP fire at a
specific time (or times) every day, month, weekday, etc. The two key pieces
of technology used to accomplish this on a Unix box are called "cron"
and "lynx." The text-based Internet browser "lynx" can be run from a Unix command line, and "cron" is a clock daemon that permits the firing of events repetitively at predetermined times.
Using Cron
To use the "cron" clock daemon, you need to create crontab files. I
am by no means a Unix programmer, but managed to get the functionality
working without too much of a hassle. If you do a search on "cron" and
"crontab" on a search engine, you should find numerous examples of how to use
this technology. I've listed the sites that I used at the bottom of this
article. The basic format of a cron entry is:
minute hour day month year command
My cron file looked like this:
00 3 * * 1-5 lynx -dump -cookies -auth=mylogin:mypassword
http://myservername.com/email/sendemail.asp
The above cron file calls the lynx command (with some parameters which I'll
cover later) at 3 a.m. every weekday.
Using Lynx
For this text-based Internet browser that can be run from a Unix
command prompt, the command I call from cron is
"lynx -dump
-cookies -auth=mylogin:mypassword
http://myservername.com/admin/sendemail.asp".
It calls that ASP that I created previously. The lynx command requires a number of parameters (see the following list). Some of these are important if you want your script to run
unattended.
-cookies
My site uses cookies, so the -cookies parameter makes lynx auto-accept
cookies.
-dump
This parameter simply dumps whatever would have been displayed on the
screen out to the command line and then exits from lynx.
-auth=mylogin:mypassword
This parameter is required if you are accessing a URL that requires a login
and password. I placed my sendemail.asp file in a secure directory (email)
so that it is not run by anyone stumbling across the URL.
Finding an ISP
For all of this to fit together and work, you need an ISP that has both a
Unix server and Microsoft server. Your ASP runs on IIS and your cron
command runs on the Unix box. Most Microsoft based ISPs that run NT or Win2K
also give you a mail server to play with that usually runs on Unix, so
you shouldn't have too much problem finding an ISP to support you. Simply
telnet into your mail server and run the "crontab -l" command, and you'll
quickly find out whether your ISP has blocked access to the command or not.
Summary
There are a number of ways that you can use the idea presented in this
Article. Targeted emails are only one of many. I have not included any of
my ASP code that actually reads from the database and sends out the email
because this topic is covered numerous times in other articles. This article focuses more on how to fire events from a shared server
environment.
Helpful Links
For information on crontab, cron, and lynx, see the following:
http://campuscgi.princeton.edu/man?crontab
http://campuscgi.princeton.edu/man?cron
http://campuscgi.princeton.edu/man?lynx
Information on the "at" command can be found at http://campuscgi.princeton.edu/man?at.
About the Author
Matthew Muller is a senior consultant with Cap Gemini Ernst & Young's
Microsoft Advanced Development Center in Bellevue, Washington. An
Australian native, Matt has lived in the United States since 1997 after studying as an exchange student at Purdue University. He has been developing Internet
applications using Microsoft-based technologies for large companies since 1998. He is also involved in the development of a number of
nonprofit Web sites, including usfooty.com, a Web site that serves as the
central point for Australian Rules Football in the United States.
He can be reached at
matt@seattlefooty.com.
|