Tuesday, August 18, 2009

Check Site Status with Perl and wget !!!

This takes a file as input with one partial url per line like google.com and then check to see if you can get to each ... the ones you can get to it prints out to screen if you want to redirect to a file just > it over there ...

#!/usr/bin/perl
#
use strict;
#
my (@Llist, $uniq, $url, $cmd);
#
open (DATA1, $ARGV[0]) or die "Can't open datafile: $ARGV[0]\n";
chomp (@Llist = );
close DATA1;

foreach $uniq (@Llist){
$url = "http://www\." . $uniq;
$cmd = `wget --spider --no-cookies -t 1 -T 10 $url 2>&1`;
if ($cmd =~ /200\ OK/) {
print $uniq, "\n";
}
}