File: win2kcpu.pl

package info (click to toggle)
netmrg 0.18.2-14
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,104 kB
  • ctags: 1,575
  • sloc: xml: 8,912; php: 7,389; sh: 4,019; cpp: 2,581; perl: 471; ansic: 338; makefile: 316; sql: 5
file content (48 lines) | stat: -rwxr-xr-x 905 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
#
# win2kcpu.pl
#
# uses snmpwalk to return the cpu load for
# the cpu requested, or the first cpu if no cpu specified
#

use strict;

# we need at least a host and a community string
if (scalar(@ARGV) < 2)
{
	print "U\n";
	exit();
} # end if only one argument

# some variables to be used later
my $host = $ARGV[0];
my $community = $ARGV[1];
my $cpunumber = 1;
my $cmdoutput;
my @outputpercpu;

if (defined($ARGV[2]))
{
	$cpunumber = $ARGV[2];
} # end if cpu number specified


# execute snmpwalk and store output
$cmdoutput = `snmpwalk -Ov -c $community $host host.hrDevice.hrProcessorTable.hrProcessorEntry.hrProcessorLoad 2> /dev/null`;
@outputpercpu = split(/\n$/, $cmdoutput);

my $i = 0;
foreach my $line (@outputpercpu)
{
	$i++;
	if ($i == $cpunumber)
	{
		$line =~ /(\d+)$/;
		print "$1\n";
		exit();
	} # end if time to output cpu info
} # end output for each cpu

print "U\n";