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

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"

    /J\

      ++ on the second answer :)

      44696420796F7520732F2F2F65206F
      7220756E7061636B3F202F6D736720
      6D6521203A29202D2D204A75657264
      

        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/;
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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://150319]
Approved by root
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (13 votes), past polls