Check a web page exists

   Share

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: , ,

  • Share/Bookmark

Related posts:

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

5 Responses to “Check a web page exists”

  1. T.R.  on March 16th, 2009

    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?

    Reply

    • yonitg  on March 16th, 2009

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

      Reply

  2. jmixx  on February 18th, 2010

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

    Reply

    • yonitg  on February 19th, 2010

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

      Reply

  3. trongtran.javadev  on July 1st, 2010

    for linux
    if [ -z $SVN_URL ]; then

    for window
    don’t known

    Reply


Leave a Reply