Check a web page exists
ShareHere 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.
Related posts:
- Check apache from command line
- Apache and MySQL on windows
- Apache Active Directory Authentication
- Test http server from windows command line
- Get Better Google Adsense Ads!
5 Responses to “Check a web page exists”
Leave a Reply


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?
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
jmixx on February 18th, 2010
Did you ever update this? I just had a need for this kind of script today…
yonitg on February 19th, 2010
@jmixx – this is not updated yet – but i will this week
trongtran.javadev on July 1st, 2010
for linux
if [ -z $SVN_URL ]; then
for window
don’t known