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 (Canon) 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'
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl script on windows node
by nikosv (Chaplain) on Apr 03, 2012 at 19:16 UTC