Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

uptime for NT/2K

by idnopheq (Chaplain)
on Apr 23, 2001 at 14:15 UTC ( #74673=sourcecode: print w/replies, xml ) Need Help??
Category: NT Admin
Author/Contact Info idnopheq
Description: uptime - show how long the system has been up

The uptime command prints the current time, the length of time the system has been up, and the number of users logged on.

REQUIRES: Date::Calc

#!/usr/local/bin/perl -w

use strict;
use vars qw ( @WhoList );
use Win32;
use Win32::NetAdmin;
use Date::Calc qw( Delta_DHMS );

my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/;

my $warnings = 0;

# Print a usuage message on a unknown option.

$SIG {__WARN__} = sub {
    if (substr ($_ [0], 0, 14) eq "Unknown option") {die "Usage"};
    require File::Basename;
    $0 = File::Basename::basename ($0);
    $warnings = 1;
    warn "$0: @_";

$SIG {__DIE__} = sub {
    require File::Basename;
    $0 = File::Basename::basename ($0);
    if (substr ($_ [0], 0,  5) eq "Usage") {
        die <<EOF;
$0 (NT Perl bin utils) $VERSION
$0 [ -h ]
    die "$0: @_";

die "Usage" if $ARGV[0];

my $Server = "";

my @Month = (

Win32::NetAdmin::LoggedOnUsers (
  or die "$^E\n";

my $Reboot = time - ( Win32::GetTickCount() / 1000 );
my @Neht = localtime ( $Reboot );
my @Won = localtime ( time );

$#Neht = 5;
my @Then = reverse @Neht;
$#Won = 5;
my @Now = reverse @Won;

my @Diff = Delta_DHMS ( 

my $UserPlural = "user";
$UserPlural = $UserPlural . "s" if $#WhoList > 0;

printf " %2d:%2d    up %d days, %2d:%2d, %2d %s\n", $Now[3], $Now[4], 
+$Diff[0], $Diff[1], $Diff[2], $#WhoList + 1, $UserPlural;


=head1 NAME

B<uptime> - show how long the system has been up


B<uptime> [ -h ]


The B<uptime> command prints the current time, the length of time the 
+system has been up, and the number of users logged on.

=head2 OPTIONS

The following options are supported:

=over 4

=item -h

Display syntax.


=head1 EXAMPLE

Below is an example of the output B<uptime> provides:

C:\> uptime
 10:10    up 0 days, 18:40,  2 users


The working of B<uptime> is not influenced by any environment variable

=head1 BUGS

B<uptime> returns an approximate uptime.  It uses the Win32::GetTickCo
+unt() function, an imprecise mechanism.  A better way to derrive the 
+last boot is to query the event log for the most recent 6005 or 6009 
+event and grab that time.  If log files are large, this can be time c

If you need this kind of resolution, use B<who -b>.

B<printf> does not seem to want to pad numbers with '0's.


It does not make sense to talk about standards in a B<uptime> manual p


    Revision 1.0  2000/06/22 10:05:57  idnopheq
    Initial revision

=head1 AUTHOR

The Perl implementation of B<uptime> was written by Dexter Coffin, I<i>.


This program is copyright by Dexter Coffin 2000.

This program is free and open software. You may use, copy, modify, dis
and sell this program (and any modified variants) in any way you wish,
provided you do not restrict others from doing the same.

=head1 SEE ALSO

=for html
<a href="who.html">who</a><p>


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://74673]
[Discipulus]: Tanktalus my comment was about how to fork & join in tk?
[marioroy]: Oh, I've might of missed Discipulus's earlier response. I had gone to bed.
[Tanktalus]: ah, I don't even have the perlmonks site open in my browser :)
Tanktalus is chatting through his cbstats application :)
[marioroy]: Perl is so much fun.
[Discipulus]: Tanktalus i recently started a Meditation about marioroy's MCE suit of modules, but is even better to see a practical question answered than responses to my meditation
[Discipulus]: good night mario!
[Tanktalus]: yeah, I saw you post about MCE - the concept looks really really cool. I wonder how well it plays with Coro :)
[Lady_Aleena]: Hi guys. I asked this earlier but got no answer. Why is this dying at -exec: my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;);
[Lady_Aleena]: The error find: missing argument to `-exec'

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-23 19:51 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.