我想用munin监视我的oki打印机,所以我正在尝试使this plugin适应我的打印机。
我的打印机http服务器中的页表是:

<table width="560" border="0" cellspacing="2" cellpadding="3">
    <tr class="sub_item_color">
        <td  class="normal" width="200" align="right" valign="bottom" rowspan="2">Media Size</td>
        <td  class="normal" width="90" align="left">Color</td>
        <td  class="normal" width="90" align="left">Color</td>
        <td  class="normal" width="90" align="left">Mono</td>
        <td  class="normal" width="90" align="left">Mono</td>
    </tr>
    <tr class="sub_item_color">
        <td  class="normal" width="90" align="left">A3/Tabloid</td>
        <td  class="normal" width="90" align="left">A4/Letter</td><td  class="normal" width="90" align="left">A3/Tabloid</td>
        <td  class="normal" width="90" align="left">A4/Letter</td>
    </tr>
    <tr class="sub_item_color">
        <td  class="normal" width="200" align="left">Total Impressions</td>
        <td  class="normal" width="90" align="right">21906</td>
        <td  class="normal" width="90" align="right">33491</td>
        <td  class="normal" width="90" align="right">2084</td>
        <td  class="normal" width="90" align="right">4460</td>
    </tr>
    <tr class="sub_item_color">
        <td  class="normal" width="200" align="left">Total A4/Letter Impressions</td>
        <td  class="normal" colspan="2" align="center"><b>Color:77303</B></td>
        <td  class="normal" colspan="2" align="center"><b>Mono:8628</B></td>
    </tr>
</table>

穆宁的剧本是这样写的:
infopage=`wget -q -O - http://root:$password@$destination/printer/printerinfo_top.htm | perl -p -e 's/\n/ /m'`
echo tray1.value    `echo $infopage | perl -p -e 's/^.+Tray\ 1\ Page\ Count\:\ \<\/TD\>\<TD\ WIDTH\=\"94\"\>([0-9]+)\<.+$/$1/'`

我怎么才能得到完整的印象呢?

最佳答案

解决方案实现为与问题中类似的Unix过滤器,由于XPath,它的可读性和声明性更强。

#!/usr/bin/env perl
use 5.010;
use strictures;
use HTML::TreeBuilder::XPath qw();
use List::Util qw(sum);
my $tree = HTML::TreeBuilder::XPath->new;
$tree->parse_content(<>);
say sum map { s[.*:][]; $_ } $tree->findnodes_as_strings('//table/tr/td[@colspan=2]/b');

wget -q -O - http://… | perl sum-total-impressions.pl

关于regex - 在bash/Perl中使用RegEx从html表中提取值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4163927/

10-10 11:26