Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Obtaining Server Uptimes using Perl

Thread Tools

Obtaining Server Uptimes using Perl

Posts: n/a

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:erfLib;
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:erfLib($Server);
print "Can't open PerfLib on $Server!\n\n";
my $objlist = {};
my $system = 2;
if($perf->GetObjectList("$system", $objlist))
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;

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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Obtaining what Web Server is running the WebSite Wayne Gibson ASP .Net 3 05-13-2005 12:20 PM
Obtaining page path when using Server.Transfer... Terry Mulvany ASP .Net 1 04-30-2004 10:17 PM
obtaining date/time values from a Time Server =?Utf-8?B?UGF0cmljaw==?= ASP .Net 1 01-29-2004 08:49 PM
Obtaining autonumber value after using recordset AddNew Roger Withnell ASP General 9 12-02-2003 02:55 PM
obtaining current username after login using forms authentication Jason \(MFT1\) ASP .Net 1 08-15-2003 06:16 PM