12 February, 2008

crontab tips on GoDaddy

This was nowhere in the GoDaddy documentation so, I though I would share a working solution.

The objective was to create a single php script which a set of scheduled crontab tasks could execute from my GoDaddy virtual dedicated server. I wanted something that ran hourly, daily, weekly and monthly.

The steps I used were:

1. Create your script in the normal way. The key element is the $_SERVER['argv']['1'] variable, which is passed from the crontab line. You could pass more than one. The second would be $_SERVER['argv']['2']. You might add this for a checksum to prevent the script running if the search engines find it. I then used the first variable in a switch group to establish the start and end date for a MySQL query that runs later. So:

switch ($_SERVER['argv']['1']) {

case "hourly": // RUNS AT *:00
$d2 = date("Y-m-d H",time()).":00:00";
$d1 = date("Y-m-d H",strtotime($d2) - 3600).":00:00";
$num = 1;
break;

case "daily": // RUNS AT 00:20
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 24 * 3600);
$num = 2;
break;

case "weekly": // RUNS AT 00:40
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 7 * 24 * 3600);
$num = 3;
break;

case "monthly": // RUNS AT 01:00
$d2 = date("Y-m-d",time() - 24 * 3600);
$d1 = date("Y-m-d",strtotime($d2) - 24 * 3600 * 365.25 / 12);
$num = 4;
break;

}

$query2 = "SELECT *
FROM `".$type[$j]."`
WHERE DATE(`".$col[$j]."`) > '".$d1."'
AND DATE(`".$col[$j]."`) <= '".$d2."'";

2. Chmod this file to 'rwx r-x r-x' to allow it to be executed by the server.

3. Add a scheduled task like this (all on one line of course):

10 0 * * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php hourly
20 0 * * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php daily
30 0 * * 1 /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php weekly
40 1 1 * * /usr/bin/php /var/www/vhosts/yourdomain/httpdocs/cron/alerts.php monthly

I have the file in a directory called cron, but you can put it where you like.

Any HTML output your script creates will then be sent to the email address set in the preferences tab where you set up scheduled tasks. This is for error reporting so make your script produce no HTML if it is working fine.

18 November, 2007

Soane.net photo gallery restored

See the photos here. Thanks to Gallery 2. See their site here

Club-host.com migrated

The basic club-host site is on the new server. See it here

17 November, 2007

Server migration complete for garfagnana-food and soane.net

I have closed the old server. Some, non-active, sites still need to be loaded on the new server, but I took the decision to complete the move as an incentive to get everything in order. All the domain routing now works, but some of the sites have to be loaded. I am gradually working my way through them.

30 October, 2007

Server migration

I have taken the plunge and started the migration to a new GoDaddy server (http://72.167.97.186/). New details:
CPU GenuineIntel, Intel(R) Xeon(R)CPU 5148 @ 2.33GHz
Operating system Linux 2.6.9-023stab044.4-smp
Plesk version 8.2.1_build82070918.10 os_FedoraCore 6

I was forever running out of memory on the old one and this will give me more speed and a supported Fedora operating system (Core 6). Also added Plesk 8.2.1, which will give me a bit more functionality over domain hosting, etc.

Transferred my parked domains yesterday.

Will move the active sites over the w/e probably, before closing the old one. Meanwhile all should be as was on the old server.


Now I just need to get to grips with Plesk...

17 August, 2007

Gallery2 added to soane.net

Great piece of free kit this, which enables you to publish your own photos. LINK

25 May, 2007

OverLIB incorporated into garfagnana-food

Another great freeware product, thanks to Erik Bosrup. LINK

21 March, 2007

Google maps integrated into garfagnana-food

What a brilliant application this is. Just could not resist integrating it into the site. It slows the whole thing down a lot though so I have put it a bit more in the background now. LINK

17 March, 2007

Soane.net redesigned

A full make-over to simplify and smarten up what had become a bit of a mess. Hope you like it... LINK

12 March, 2007

Switched host to GoDaddy virtual dedicated server

Finding shared hosting a bit too constrained and in particular preventing me from providing a service that a client particularly wanted, I took the plunge and bought GoDaddy's virtual dedicated server. So now I have 10GB of a linux box in Scottsdate Arizona, running Red Hat Fedora Core 4, Apache 2.0.13, PHP 5.0.4, MySQL 4.1.20. LINK

22 October, 2006

Started development of garfagnana-food.com

This is a good food guide for the Garfagnana region of Tuscany. I could never remember what was available, when it was open and I found myself not trying different places as a result. So the idea was selfish, but I thought it might have wider benefits. Still developing, though the basics work. LINK

08 October, 2006

Shared hosting by GoDaddy

CWH unable to offer the flexibility I was looking for on sub-domains, I bought some shared linux capacity with GoDaddy. So far so good.

28 January, 2006

Club-host basic launched

Prompted by an enquiry from a club, I developed a "out of the box" or "plain vanilla" starter site for clubs looking for a really cheap entry into the www with no programming or HTML skills needed. The terms can be found on club-host.com. LINK

02 January, 2006

Designed and implemented sew-linda.xnet.cc

This was a commission for my sister-in-law who makes brilliant curtains and furnishings and wanted to start a business. LINK

13 November, 2005

Designed and implemented juniorpenguins.club-host.com

This was a clone of the main penguins site but for the junior section. Having built it, there was not much interest and it really never took off. LINK

10 August, 2005

Purchased xnet.cc

I was having trouble with an extranet application and decided to have a go at fixing it myself using this domain. LINK

25 October, 2004

Designed and implemented mailer.club-host.com

This was a specific application to allow clubs and societies to communicate more easily by email, giving the user the choice over what to receive when and taking the maintenance chore out of mail lists (a problem I had constantly at Wandsworth Swimming Club). LINK

08 April, 2004

Designed and built club-host.com

The idea here was to help clubs and societies to join the 'information age' with the expertise I had developed with Wandsworth Swimming Club's web site. LINK

12 August, 2003

Hosting by Christian Web Host

Bought a linux shared server package with CWH. Absolutely delighted with the support and service. LINK

10 August, 2003

Bought workster.org and workster.info

Confidential project still under consideration.