<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Matthew Steven Kelly &#187; scripting</title>
	<atom:link href="http://www.matthewstevenkelly.com/blog/tag/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://www.matthewstevenkelly.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 23 Jul 2010 00:18:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Task Schedule Web Script From Windows</title>
		<link>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html</link>
		<comments>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html#comments</comments>
		<pubDate>Tue, 10 Feb 2009 03:26:40 +0000</pubDate>
		<dc:creator>Matthew Steven Kelly</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.matthewstevenkelly.com/blog/?p=425</guid>
		<description><![CDATA[If your website hosting is of the Linux variety, you know you can schedule scripts to automatically run using cron jobs. But what if your servers are all of the Windows variety? Not a problem, Windows provides the Windows Task Scheduler. Lets say you have a php script that sends out emails to a newsletter [...]]]></description>
			<content:encoded><![CDATA[<p>If your website hosting is of the Linux variety, you know you can schedule scripts to automatically run using cron jobs. But what if your servers are all of the Windows variety? Not a problem, Windows provides the Windows Task Scheduler.</p>
<p>Lets say you have a php script that sends out emails to a newsletter list, but because you do not want to flood your email servers, you would like to have the server send out (20) emails every 30 minutes to keep your daily total under 1000 emails/day. You could generate a script that every time it was executed grabbed the next 20 emails from a database list and send them a predefined email.</p>
<p>Or if you have a database that has a large amount of volume, so to conserve space you only want to keep data that is less than 30 days old. You could create a script that executes a query to delete any content older than 30 days. With the task scheduler, you could have this script run every night.</p>
<p>Or if you have a production database and need to email a report out every hour, you could create a script to do so and task schedule it.</p>
<p>Or any other task you wish to have repeated on a scheduled basis and can easily script the task. This is a great tool for developers who are only familiar with scripting languages like PHP, ASP, etc and can complete advanced tasks in them that would otherwise be done by coding a C++ or C# server application.</p>
<p>Lets go with scheduling the email script example above for a walk through on setting up the Windows Task Scheduler.</p>
<p>On the Windows server (note this does not have to be the web server &#8211; it can be any Windows machine that will be running 24/7 to be able to execute the script when scheduled) go to &#8220;Start | Control Panel | Scheduled Tasks&#8221;.</p>
<ol>
<li>Click the Add Scheduled Task button</li>
<li>Click Next</li>
<li>Select Internet explorer from the list and click Next</li>
<li>Select Perform this task Daily (we&#8217;ll change it later) and click Next</li>
<li>Click Next on the task start time</li>
<li>Enter your username and password of the computer</li>
<li>Check the open advanced properties checkbox and click Finish</li>
</ol>
<p>In advanced properties</p>
<ol>
<li>Add &#8220;www.mywebsite.com/mail.php&#8221; after &#8220;C:\PROGRA~1\INTERN~1\iexplore.exe&#8221; in the &#8220;Run&#8221; Section. The field will look like this: &#8220;<i>C:\PROGRA~1\INTERN~1\iexplore.exe www.mywebsite.com/mail.php</i>&#8220;</li>
<li>Click on the schedule tab and click advanced</li>
<li>Check &#8220;Repeat Task&#8221; and say every 30 minutes for 24 hours.</li>
<li>Click OK</li>
<li>Click OK</li>
<li>Enter the Windows user name and password again</li>
</ol>
<p>Internet explorer will pop up and execute the script every 30 minutes now.</p>
<p>Need the script to have a few layers of security? Here are a few things you can add:</p>
<ul>
<li>Utilize SSL encryption and setup the task scheduler to access the page via https:// instead of http:// this ensures any data transmitted between the web server and computer running the task scheduler is encrypted.</li>
<li>Have the web page look for a specific cookie on the computer making the request to execute the script. Then add a method to the script to allow for the one time creation of the cookie, such as <i>mail.php?generatecookie=1</i>. Now on any computer you need to run the task scheduler, first generate the cookie on the computer, then run the scheduler.</li>
<li>Have the script check the IP address of where the request is coming from and only allow it to execute if it is the IP address of the server running task scheduler. With PHP you can detect the IP address of where the web request is coming from using &#8220;$_SERVER['REMOTE_ADDR']&#8221; (note: only works if you have a static IP address and keep in mind IP addresses can be spoofed).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.matthewstevenkelly.com/blog/random/task-schedule-web-script-from-windows.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
