Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

system commands

by Anonymous Monk
on Mar 08, 2002 at 14:05 UTC ( #150319=perlquestion: print w/ replies, xml ) Need Help??
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??

Comment on system commands
Download Code
Re: system commands
by demerphq (Chancellor) on Mar 08, 2002 at 14:16 UTC
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"


      ++ on the second answer :)


        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


        print "profeth still\n" if /bird|devil/;
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.


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.

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

    -- grummerX

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://150319]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-09-01 14:04 GMT
Find Nodes?
    Voting Booth?

    My favorite cookbook is:

    Results (13 votes), past polls