Linux Admin Steps Into Management

Check a web page exists

Here is a short method to check if a web page exists from a perl script,
this script will test the existense of a page and do something as a result:

#!/usr/bin/perl
use LWP::Simple;
print “Content-Type: text/html\n\n”;

$url = “http://site.com/“;

if (head($url)) {
# ok document exists
print “OK: found $url”;
} else {
# something is not well
print “PROBLEM: $url is missing”;
}

This script is using the libwww-perl package.

Technorati Tags: , ,

Related posts:

  1. Check apache from command line
  2. Apache and MySQL on windows
  3. Test http server from windows command line
  4. Apache Active Directory Authentication
  5. Get Better Google Adsense Ads!
Tag: , ,
  • T.R. says:

    I would probably extend it to check the returned error code as well.
    For getting a response doesn’t necessarily mean that all is well. It can be a redirect command or possibly some other type of error. Would you also like to follow a chain of redirects? (you should detect and avert cyclic redirects).
    One more question I’d be curious to know is whether LWP supports HTTPS protocol as well?

    March 16, 2009 at 6:59 pm
    • yonitg says:

      Thanks T.R. – I’ll look at adding more functions to the script later on,
      welcome to my new blog :)

      March 16, 2009 at 8:18 pm
  • jmixx says:

    Did you ever update this? I just had a need for this kind of script today…

    February 18, 2010 at 7:33 pm
    • yonitg says:

      @jmixx – this is not updated yet – but i will this week

      February 19, 2010 at 3:54 pm
  • trongtran.javadev says:

    for linux
    if [ -z $SVN_URL ]; then

    for window
    don’t known

    July 1, 2010 at 10:10 am

Your email address will not be published. Required fields are marked *

*