// archives

Scripts

This category contains 3 posts

Shell Script: Instantly restart a process or script if it dies

Recently I faced a task in a project, wherein I was asked to ensure that a script (a PHP script) must be always running, to the extent that if it dies, it must restart immediately.

Though the script was fairly tested to handle error conditions, still there could be a few unforeseen situations . This is because the script fetches data from a third party service provider and also relies on constant connectivity with the service provider for real time data.

The script was to run unattended on a Linux server. Read the rest of this entry »

GD Star Rating
loading...
GD Star Rating
loading...
Share

Web Scraping with Firefox and PHP, using XPath

Last year, I faced two projects which required automated Web scrapping – to aggregate content from web pages. I evaluated different methods for Web scraping with varied level of success. Thanks to the changing structure of Web pages, non well-formed pages and URL redirects.

Amongst using regular expressions and DOM (Document Object Model) parsing, I used XPath too. XPath works great for well-formed Web pages. Read the rest of this entry »

GD Star Rating
loading...
GD Star Rating
loading...
Share

Simple script to alert about inaccessible servers

Following is a simple script, written in PHP, which will send an E-mail alert to you when one or more of your Web servers is inaccessible.

<?php
/* things to edit/change */

$fileToFetch = "isalive.txt";
$mailTo = "shekhar@it4enterprise.com";
$mailFrom  = "alert@it4enterprise.com";

$websites = array(
"Website 1" => "http://www.website1.com",
"Website 2" => "http://www.website2.com",
"Website 3" => "http://www.website3.com"
);

/* end of things to edit/change */

foreach($websites as $name=>$value)
  if(!($fp = @fopen($value."/".$fileToFetch,"r")))
    mail($mailTo,"WEBSITE DOWN: ".$name,"WEBSITE DOWN: ".$name,"From: ".$mailFrom);

?>

Read the rest of this entry »

GD Star Rating
loading...
GD Star Rating
loading...
Share

Recent Tweets

Follow Me on Twitter