12 May 2011

Scheduled task ping for plesk in Windows

I've been moving several domains to a Windows cloud hosting package at http://www.webhosting.uk.com/. I'm currently using Cloud Beginner hosting that gives 10 domains and a dedicated IP address for £12/month. This package lets us run DotNetNuke (DNN) sites - and fast too as there is not much contention on the included SQL Server databases. The cloud is UK based so the ping time is less from the UK and nearby.

The account is run using Windows plesk which lets you control most things. However intervention is often needed from the webhosting.uk.com staff. They are usually very responsive and competent on their Live Chat service. Typical requests include setting ASP.NET modify permissions for the Network Service user and setting Application Starting Points. You need to insist that you get the dedicated IP address if you've asked for it. Email is included using the Horde web client, which isn't great; perhaps using Google Apps for email might be the best solution. No web stats package is included. Nor are file or database backups.

For one domain, one task that I needed to do was to set up scheduled tasks to ping various URLs. While this could be done externally, I decided to use the Plesk scheduled task feature. When FTPing in, the main site is at /httpdocs/. The scheduled task VBS scripts should be placed in /cgi-bin/

Using a couple of resources on the Internet, I put together this script, called pingurls.vbs:

Call DoScheduledTask()

Sub DoScheduledTask()
On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("E:\inetpub\vhosts\mydomainname.com\cgi-bin\urls2ping.txt", ForReading)

Dim URL
Do Until objFile.AtEndOfStream
URL = objFile.ReadLine
if Len(URL)>0 then PingURL(URL)
Loop
objFile.Close

end sub

sub PingURL(URL)

Dim RequestObj
Set RequestObj = CreateObject("Microsoft.XMLHTTP")
'Open request and pass the URL
RequestObj.open "POST", URL , false
'Send Request
RequestObj.Send
'cleanup
Set RequestObj = Nothing

End Sub

This script reads a text file urls2ping.txt, also in the /cgi-bin/ directory. Each line contains a URL to be pinged.

How do you know what absolute path to use to get to the text file? This ASP.NET code, say in MyPath.aspx, will tell you the path it is running from:
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load()
lblPath.Text = Request.MapPath("~")
End Sub
</script>
<html>
<head>
<title>Web app path using Request.MapPath</title>
</head>
<body>
<asp:Label ID="lblPath" Runat="server" />
</body>
</html>


The final stage is to set up the scheduled task in plesk. This is straight forward using [Scheduled Tasks] then [Add New Task]. The Path to Executable file should be similar to that used above, ie E:\inetpub\vhosts\mydomainname.com\cgi-bin\pingurls.vbs. Set the times you want the task to run.

2 comments:

Daniel Obryk said...

Hi Chris, sorry for commenting on old post, I've just moved my all websites to webhosting.uk.com and they are mostly ok but I have a huge problems with them not truncating logs, and my all the websites periodically goes down. How did you overcome that ?

Chris Cant said...

You are right: the site disk usage increases as the database logs aren't automatically truncated. I've set up plesh to tell me when the site disk is getting full; then I simply send them a support ticket asking them to truncate them.

The cloud package runs an old version of plesk which is annoying.

In some situations various permissions get reset which is also annoying.