On 11/17/06, Mário Gamito <[EMAIL PROTECTED]> wrote:
Hi,
I need to write a script that detects when a file is created in a certain
directory and then e-mail it.
I thought about fam. Problem is the machine is a AIX and it doens't have
fam.
I think in PERL is possible to do the trick.
I don't know in advance the name of the files that are created.
Any help would be appreciated.
Mario,
See perldoc -f -X
while (1) {
sub_to_check_and_email_file() if -e "$yourdir/$yourfile";
sleep 1; #or however often you want to poll
}
For the actual emailing bit, check CPAN. Net::SMTP, Mail::Mailer,
Mail::Sendmail, and MIME::Lite would all be options; there are others.
All of Tom's caveats apply though: before you figure out what to do
with the file once it's created, you need to settle on a working
definition of "create." You should also do some sanity checking on the
file. Looking at a log file is a good solution if there is one. if
not, is there some EOF marker you can look for or do you have a
reasonable expectation of the length?
You'll also want to think about how you want to make sure the polling
happens. Do you want to daemonize the process and control it through
init? Run a cron job periodically to poll? Set it up as an infinte
loop and and have a cron job check in every once in a while and make
sure it's still running?
Those decisions will gretly affect the shape of the script you end up writing.
HTH,
-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential
daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org
values of β will give rise to dom!