Here is a script I use to check system up time. You can specify a remote
server as an argument and it will remotely check the uptime for that server.
This goes into the perfmon stats and gets the information from there.

Keith
----------------------cut here-------------------------------------
#!c:/perl/bin

# ********************************************************************
# * SystemUpTime.pl                                                  *
# * Copyright (C) 1998 by Jutta M. Klebe                   010398 JK *
# * All rights reserved.                               LU: 250898 JK *
# ********************************************************************
# * $Author:: Jmk                                                  $ *
# * $Date:: 25.08.98 23:02                                         $ *
# * $Archive:: /Jmk/scripts/saa/SystemUpTime.pl                    $ *
# * $Revision:: 2                                                  $ *
# ********************************************************************

use Win32::PerfLib;

($machine) = @ARGV;

$perf = new Win32::PerfLib($machine);
if(!$perf)
{
    die "Can't open PerfLib of $machine!\n";
}
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 "\t$counter total seconds\n";
        print "\t$day day(s) $hour hour(s) $minute minute(s) $seconds
second(s)\n";
        print "\tSystem was last started on $backday\n";
        last;
    }
    }
}


# ********************************************************************
# $History: SystemUpTime.pl $
# 
# *****************  Version 3  *****************
# User: Kbm          Date: 28.02.2002 Time: 09:02
# Added line to show you what day the system was rebooted.
#
# *****************  Version 2  *****************
# User: Jmk          Date: 25.08.98   Time: 23:02
# Updated in $/Jmk/scripts/saa
# fixed bug in Win32::PerfLib module. This showed a bug in this script.
# Denominator and Timebase weren't correct.
# 
# *****************  Version 1  *****************
# User: Jmk          Date: 26.05.98   Time: 8:20
# Created in $/Jmk/scripts/saa
# Retrieve the system up time for any (NT) computer
# ********************************************************************
-----------------------------cut here---------------------------------

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to