[Omaha.pm] Perl solution request
Jay Hannah
jay at jays.net
Fri Nov 10 13:35:17 PST 2006
Paul Hanson wrote:
> I know this can be done, but it's implementation is boggling me.
>
> We have a ****ton of IBM servers, many of which are nearing their 'put
> out to pasture' date. The issue is finding out which ones are close
> and which should be there by now. Well, IBM conveniently has a web
> page dedicated to this. However, it's not easy to script. I've made
> several valiant but failed attempts with curl, lynx, links, etc.
>
> I remember reading somewhere about a HTML::Mechanize I think it's
> called, where you are able to get information from a page. However,
> with my limited Perl skills (=0) and my lack of time I was wondering
> if you wouldn't mind looking in to this.
>
> The URL is
>
> http://www-307.ibm.com/pc/support/site.wss/warrantyLookup.do?type=XXXX&serial=XXXXXXX&country=897&iws=off
>
> Where "X" could be the machine type and the serial number I've been
> able to manually plug in these with success.
>
> Samples:
> 8676 - KP-DRC21
> 8843 - 99GTK75
>
> Would you have time to look into this and help me find a solution?
> Ideally, it would take a text file as input for the two variables and
> spew the info out into a new text file.
>
> If you have further questions or just want to mock me, feel free to email.
>
> Thanks!
> -Paul
Hi Paul --
Here's what I could do for you in 15m. WWW::Mechanize is pretty cool. From this point forward you'll need to parse the super-ugly humongous HTML table that IBM throws your data into. Perhaps try HTML::TableExtract? Should be pretty easy...?
I hope that helps you get going.
Cheers,
j
$ cat j.pl
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url = "http://www-307.ibm.com/pc/support/site.wss/warrantyLookup.do?type=__AAA__&serial=__BBB__&country=897&iws=off";
open (IN, "warranty_list.txt");
while (<IN>) {
chomp;
my ($type, $serial) = split " - ";
my $tmpurl = $url;
$tmpurl =~ s/__AAA__/$type/;
$tmpurl =~ s/__BBB__/$serial/;
print "Fetching $tmpurl...\n";
$mech->get( $tmpurl );
my @lines = split "\n", $mech->content;
foreach (@lines) {
if (/Expiration date/) {
# This is where your data is... Hand $_ into HTML::TableExtract?
# s/<.*?>//g; # throw all HTML away...
print;
last;
}
}
print "\n\n";
}
$ cat warranty_list.txt
8676 - KP-DRC21
8843 - 99GTK75
$ perl j.pl
Fetching http://www-307.ibm.com/pc/support/site.wss/warrantyLookup.do?type=8676&serial=KP-DRC21&country=897&iws=off...
<table width="427" border="0" frame="border" cellspacing="0" cellpadding="0"><tr valign="top"><td valign="top" width="159"><b>Type:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120"><b>Model:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140"><b>Serial number:</b></td></tr><tr valign="top"><td valign="top" width="159">8676</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120">61X</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140">KPDRC21</td></tr><tr valign="top"><td colspan="5" valign="top"><br></td></tr><tr><td width="159"><img border="0" width="1" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm
.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr><tr valign="top"><td valign="top" width="159"><b>Status:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120"><b>Expiration date:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140"><b>Location:</b></td></tr><tr valign="top"><td valign="top" width="159">Out of warranty</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120">2006-09-08</td><td valign="top" width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140">UNITED STATES</td></tr><tr><td width="159"><img border="0" width="1" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="4"><img b
order="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr><tr><td width="159"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td valign="top" align="left" width="10"><img alt="Warranty service upgrades & maintenance services" border="0" height="16" width="16" src="//www.ibm.com/i/v14/icons/fw_bold.gif"></td><td valign="top" align="left"><b><a class="fbox" href="http://www.ibm.com/support/warranties/us/">Warranty service upgrades and maintenance services</a></b></td></tr></table></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr></table><table width="427" border="0" frame="border" cellspacing="0" cellpadding="0"><tr valign="t
op"><td valign="top"><br></td></tr><tr valign="top"><td valign="top"><b>Description:</b></td></tr><tr valign="top"><td valign="top">This product has a three year limited warranty and is entitled to parts, labor and on-site repair service. Service is available Monday-Friday, except holidays, with a next business day response objective. Many parts can also be delivered to you using the Customer Replaceable Unit (CRU) method.</td></tr></table> <table width="427" border="0" cellspacing="0" cellpadding="0">
Fetching http://www-307.ibm.com/pc/support/site.wss/warrantyLookup.do?type=8843&serial=99GTK75 &country=897&iws=off...
<table width="427" border="0" frame="border" cellspacing="0" cellpadding="0"><tr valign="top"><td valign="top" width="159"><b>Type:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120"><b>Model:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140"><b>Serial number:</b></td></tr><tr valign="top"><td valign="top" width="159">8843</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120">2RU</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140">99GTK75</td></tr><tr valign="top"><td colspan="5" valign="top"><br></td></tr><tr><td width="159"><img border="0" width="1" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm
.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr><tr valign="top"><td valign="top" width="159"><b>Status:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120"><b>Expiration date:</b></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140"><b>Location:</b></td></tr><tr valign="top"><td valign="top" width="159">In warranty</td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="120">2009-03-31</td><td valign="top" width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td valign="top" width="140">UNITED STATES</td></tr><tr><td width="159"><img border="0" width="1" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="4"><img borde
r="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr><tr><td width="159"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td valign="top" align="left" width="10"><img alt="Warranty service upgrades & maintenance services" border="0" height="16" width="16" src="//www.ibm.com/i/v14/icons/fw_bold.gif"></td><td valign="top" align="left"><b><a class="fbox" href="http://www.ibm.com/support/warranties/us/">Warranty service upgrades and maintenance services</a></b></td></tr></table></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="120"></td><td width="4"><img border="0" width="4" height="1" alt="" src="//www.ibm.com/i/c.gif"></td><td width="140"></td></tr></table><table width="427" border="0" frame="border" cellspacing="0" cellpadding="0"><tr valign="top">
<td valign="top"><br></td></tr><tr valign="top"><td valign="top"><b>Description:</b></td></tr><tr valign="top"><td valign="top">This product has a three year limited warranty and is entitled to parts, labor and on-site repair service. Service is available Monday-Friday, except holidays, with a next business day response objective. Many parts can also be delivered to you using the Customer Replaceable Unit (CRU) method.</td></tr></table> <table width="427" border="0" cellspacing="0" cellpadding="0">
More information about the Omaha-pm
mailing list