I am looking to collect the value of <UB>
using wget: This the output of my wget
<FPT>0</FPT> <UB>13.5</UB>
And I am looking to gather the value 13.5(that changes) this is what I have so far:
##session wget
my $url= 'wget http://link';
my $html_page = system "wget -S -O - $url";
if($debug){printf "This is a value : $html_page\n";}
#we collect the battery state of the group
use strict;
open (UB, $url);
while (my $volt_batt = <UB>)
{
if($volt_batt < 13){
$retour = $ERRORS{'CRITICAL'};
$output = "CRITICAL - Battery Volt too low: $volt_batt V (<13 V) | batt_volt=$volt_batt\n";
}
else{
if ($volt_batt >= 13){
$output ="OK, Battery Volt: $volt_batt V (>=13V) | batt_volt=$volt_batt\n";
}
}
}
system "$output";
exit $retour;
This doesn't do what you want:
my $html_page = system "wget -S -O - $url";
You want to use readpipe
(aka qx`...`
aka ``
).
my $html_page = `wget -S -O - $url`;
Except the above suffers from a code injection bug. Fixed:
use Shell::Quote qw( shell_quote );
my $cmd = shell_quote( "wget", "-S", "-O", "-", $url );
my $html_page = `$cmd`;
You could also avoid the shell entirely by using the following:
my @cmd = ( "wget", "-S", "-O", "-", $url );
my $html_page = do {
open my $pipe, "-|", @cmd;
local $/;
<$pipe>
};
[There are numerous other errors.]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.