http://www.perlmonks.org?node_id=150319

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Okay here is my unix script for checking uptime:
uptime | awk '{if ( $3 < 1 ) print "Server rebooted in last 24 hours"}
Two questions:
1. How would perl handle this (especially the awk part)??
2. How and what command in Perl would be used on an NT to determine when a server was last rebooted??

Replies are listed 'Best First'.
Re: system commands
by gellyfish (Monsignor) on Mar 08, 2002 at 14:17 UTC

    The answer to your firsts question is something like :

    #!/usr/bin/perl -w use strict; my @uptime = split ' ', `uptime`; print "Server rebooted in last 24 hours" if ( $uptime[2] < 1 );
    The answer to your second question is simply :
    print "Server rebooted in last 24 hours"

    /J\

        LOL, I`m sorry, I thought I read:
        `If you only reboot every day then Id say you have service packs to install` ...

        Which also would have made a lot of sense :))

        I need a coffee

        GreetZ!,
          ChOas

        print "profeth still\n" if /bird|devil/;
      ++ on the second answer :)

      44696420796F7520732F2F2F65206F
      7220756E7061636B3F202F6D736720
      6D6521203A29202D2D204A75657264
      

Re: system commands
by grummerX (Pilgrim) on Mar 08, 2002 at 15:13 UTC
    This script from CPAN's script repository should help with question 2. It looks at NT's event log to see when the system started. Works like a charm on my Win2k box.

    Update:
    rdfield beat me to the punch. Same script, different locations, but the CPAN version has some documentation if you want it.

    -- grummerX

Re: system commands
by demerphq (Chancellor) on Mar 08, 2002 at 14:16 UTC
Re: system commands
by rdfield (Priest) on Mar 08, 2002 at 15:02 UTC
    There is a Perl script to check the uptime of a Win32 box here.

    rdfield