Obtaining Server Uptimes using Perl

A

Aaron

Hi,

Have been playing around the following script in an attempt to obtain
server uptimes for servers in a mixed (Win2K/NT4) Domain, the script
seems to find all the servers (PDC, BDC & Standalones) in the Domain
but doesn't report the uptime if all three Win32::NetAdmin::GetServers
lines are used at the same time, if I "rem" out one (say the PDC one)
it works with the other two?

Can anyone point me in the right direction???

Thanks in advance...

#!/usr/bin/perl -w

use Win32::perfLib;
use Win32::NetAdmin;

my ( @Servers1, @Servers2, @Servers3, $Server, $Domain, );
$Domain = ( "EDUCATION" );

Win32::NetAdmin::GetServers( '', $Domain, SV_TYPE_DOMAIN_CTRL |
0x00000008, \@Servers1 ); # PDCs
Win32::NetAdmin::GetServers( '', $Domain, SV_TYPE_DOMAIN_BAKCTRL |
0x00000010, \@Servers2 ); # BDCs
Win32::NetAdmin::GetServers( '', $Domain, SV_TYPE_SERVER_NT |
0x00008000, \@Servers3 ); # STANDALONE

foreach $Server ( @Servers1, @Servers2, @Servers3 ) {
print "$Server\n\n";
$perf = new Win32::perfLib($Server);
if(!$perf)
{
print "Can't open PerfLib on $Server!\n\n";
next;
}
my $objlist = {};
my $system = 2;
if($perf->GetObjectList("$system", $objlist))
{
$perf->Close();
my $Counters = $objlist->{Objects}->{$system}->{Counters};
foreach $o ( keys %{$Counters})
{
$id = $Counters->{$o}->{CounterNameTitleIndex};
if($id == 674)
{
$Numerator = $Counters->{$o}->{Counter};
$Denominator = $objlist->{Objects}->{$system}->{PerfTime};
$TimeBase = $objlist->{Objects}->{$system}->{PerfFreq};
$counter = int(($Denominator - $Numerator) / $TimeBase );
$seconds = $counter;
$day = int($seconds/(60*60*24)); $seconds %=60*60*24;
$hour = int($seconds/(60*60)); $seconds %=60*60;
$minute = int($seconds/60); $seconds %=60;
$backday=localtime(time-$counter);

print "Server $Server was last restarted on $backday\n";
print "Uptime is $day day(s) $hour hour(s) $minute minute(s)\n\n";

}}}}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top