Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Perl script on windows node

by kaka_2 (Sexton)
on Apr 03, 2012 at 08:08 UTC ( #963189=perlquestion: print w/replies, xml ) Need Help??
kaka_2 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Experts, I am into monitroing solution and good with shell scrpting but perl is just new to me. i am looking for a help from you guys. i need a perl script which run on windows server and do the following. 1. Check if a File abc was modified or not in last X minutes. if yes check next condition else action. 2. Check if the size of file is greater than XXX KB/MB/GB. if it not check next else action. Your help will really appriciated.

Replies are listed 'Best First'.
Re: Perl script on windows node
by tobyink (Abbot) on Apr 03, 2012 at 08:22 UTC

    Read the perlfunc sections about "-X", "stat" and "time".

    use 5.010; use strict; my $modified_within = 60 * 5; # 5 minutes my $size_limit = 1024 * 1024 * 2; # 2 MB my $file = "/some/file/name"; if ([stat $file]->[9] > time - $modified_within) { if (-s $file > $size_limit) { say "File is recent, and over size limit"; } else { say "File is recent, but not over size limit"; } } else { say "File is not recent"; }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Hi Tobyink, First of all thanks for taking time and writing the codes. i have perl v 5.8 installed on my server which comes with the application itself and when i execute the script it says it require 5.10 and fails during compilation. Is it possible to make it work with the version i have? Thank You. KAKA

        say() is the only feature being used from 5.10, so all you need to do is replace all instances of 'say' with 'print'. To keep the output the same, add a newline character (\n) to the end of each quoted string you are printing out.

        EDIT: As pointed out by ww, I should have explicitly stated that along with replacing say with print, the 'use 5.10' line should be removed as well. Thanks!

Re: Perl script on windows node
by nikosv (Chaplain) on Apr 03, 2012 at 19:16 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://963189]
Approved by Corion
[ovedpo15]: maybe even better question is if it possible to pash element to array from left. I mean that the element will enter array[0] and all other elements will move right +1

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-03-24 21:24 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.