Two primary methods immediately come to mind:
- Start a daemon type script that always sits there running, and it checks, sleeps, checks, sleeps, etc
- Have a script that runs once and checks, and execute it periodically with cron or windows scheduler or whatever you have a vailable on XP.
Assuming you have a scheduling means, I would say the second is the better method -- something isn't always running (your efficiency concern), and it's more robust becuase you don't have to worry about the job getting hung or killed.
Two methods pop to mind for the actual "checking" part, too:
- Check the directory for files created in the last N minutes.
- Keep a state file (maybe look at Cache::FileCache; and also useful related info in the recent best way to keep a simple count? about storing data between runs) that is the last time you ran and what files existed, and compare against that. (or store the last timestamp you checked, and check for files created affter that)
Be sure to reference the
File::Find module as well as the -X and stat sections in the perlfunc manpage.
Update: Here's an actual one-liner solution i used out of a linux crontab once (convenient cause cron takes care of emailing you iff there's output)--this is the shell script wrapping it (I don't necessarily recommend this, but might have some reference value):
# USAGE: touchedCheck filename [minutes]
#
# Exit Value: 0 if file was touched; 1 if not touched.
#
# Will print info about the file iff it changed in the last N minutes.
# Otherwise prints nothing.
#
# Intended for crontab use, such as:
# 0 * * * * touchedCheck /tmp/some_file.txt 60
#
/usr/bin/perl -e '$f=shift;$N=shift||60; printf("%s was changed %d min
+utes ago.\n%s", $f, $x/60.0, `/bin/ls -lart $f`) && exit(0) if ($x =
+(time - (stat($f))[9])) <= 60*$N; exit(1)' $1 $2
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.