[mrtg] SV: Re: the perl script generates crap characters ("88" He x: 38 38 instea d of just 88)
Malmgren, Henrik
Henrik.Malmgren at etu.ims.se
Wed Apr 18 16:18:05 MEST 2001
Well, i think i wrote the mail abit wrong.
If i run my perl scrip, it returns for ex 13, thats ok. But when i call that
script with snmp, it types it as string not integer.
like this:
su-2.04# perl mrtgstat.pl cpu
13
su-2.04#
Now a do i snmpwalk:
su-2.04# snmpwalk localhost public .1.3.6.1.4.1.2021.51
enterprises.ucdavis.51.1.1 = 1
enterprises.ucdavis.51.2.1 = "cpu" Hex: 63 70 75
enterprises.ucdavis.51.3.1 = "/home/mrtg/mrtgstat.pl cpu"
enterprises.ucdavis.51.101.1 = "Useless use of a variable in void context at
/ho
me/mrtg/mrtgstat.pl line 38."
enterprises.ucdavis.51.101.2 = "13" Hex: 31 33
enterprises.ucdavis.51.102.1 = 0
su-2.04#
See, it generates ""13" Hex: 31 33" as value, i just want plain 13
the perl script looks like this:
#!/usr/bin/perl
#
@temp = `vmstat`;
$values = $temp[2];
@split_values=split (/ +/,$values);
@split_values;
#
#########################################################
# If no arg, print Usage otherwise go to choise function!
if ($ARGV[0]){
choise($ARGV[0]);
} else {
usage();
}
######### Sub begin here ###############
#
sub choise {
if ($_[0] eq "cpu") {
$cpusum = $split_values[17] + $split_values[18];
chomp($cpusum);
$cpusum = int($cpusum);
print "$cpusum";
exit $cpusum;
}
elsif ($_[0] eq "cpuid") {
$idcpusum = $split_values[19];
exit $idcpusum;
}
else { &usage(); }
}
sub usage {
print "\nUsage: $0 <output type>\n";
print "Output type:\n\tmem = Free mem\n\t";
print "swap = amount of memory swaped to disk\n\t";
print "cpu = total cpu usage in % (user + system time)\n\t";
print "cpuid = cpu ideling\n\n";
}
I want the output as iteger, not string! how will i manage that??
Thanks
/Henrik!
-----Ursprungligt meddelande-----
Från: Glenn Forbes Fleming Larratt [mailto:glratt at rice.edu]
Skickat: den 18 april 2001 14:59
Till: 'mrtg at list.ee.ethz.ch'
Ämne: [mrtg] Re: the perl script generates crap characters ("88" Hex: 38
38 instea d of just 88)
Try this (the regular expression matches on a value in quotes followed by
"Hex:", and returns into $1 the value within the quotes):
$idsum = $split_values[19];
if($idsum =~ /\"(\d+)\"\s+Hex:/ )
{ $idcpuout = $1; }
else
{ $idcpuout = $idsum; }
print "$idcpuout\n";
On Wed, 18 Apr 2001, Malmgren, Henrik wrote:
> $idsum = $split_values[19];
> $idcpuout = int($idsum);
> print "$idcpuout\n";
Glenn Forbes Fleming Larratt
Rice University Network Management
glratt at rice.edu
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
############################################################################
#########
For Your safety this e-mail message has been scanned for Viruses and Content
and cleared
by MailMarshal. For more information please visit www.marshalsoftware.com or
send a
message to postmaster at ims.se.
############################################################################
#########
#####################################################################################
For Your safety this e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal. For more information please visit www.marshalsoftware.com or send a
message to postmaster at ims.se.
#####################################################################################
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the mrtg
mailing list