Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Trigger the execution!

by tart (Beadle)
on Jul 22, 2010 at 01:22 UTC ( #850750=perlquestion: print w/replies, xml ) Need Help??
tart has asked for the wisdom of the Perl Monks concerning the following question:

I am newbie's to Perl and I am wondering if there are any ways to trigger the
execution of (Perl script) without typing command(perl or running
through corn job.
I got a file in /home/tart/config.cfg
When some one updates this (config.cfg) file and save his/her updates I want the Perl script ( to run
Any ideas?


I was wondering if some how I trigger the execution of perl script I was thinking of checking the file modified date!
BUT if its not possible to trigger the execution of perl script then better leave it! just the wild thinking...

Thanks eighty-one your suggestion appreciate!;-)

Replies are listed 'Best First'.
Re: Trigger the execution!
by cdarke (Prior) on Jul 22, 2010 at 07:22 UTC
    If you are using Linux you can monitor the directory using Linux::Inotify2. For example:
    use Linux::Inotify2; my $target = '/home/tart'; my $in2 = Linux::Inotify2->new(); die "Inotify2: $!" if (! defined $in2 ); $in2->watch ($target, IN_CLOSE_WRITE, \&translate_event) or die "watch: $!"; $in2->poll while 1; # blocking call # User written callback sub translate_event { my ($ev) = @_; if ($ev->fullname eq 'config.cfg') { # File was written to (and closed), so run the script system(; # or whatever if ($?) { # Oops, it failed } } }
Re: Trigger the execution!
by JavaFan (Canon) on Jul 22, 2010 at 01:44 UTC
    That's not a Perl question.

    And unless you have a file system that allows you to have hooks on modifications, the answer is that there are no ways.

Re: Trigger the execution!
by eighty-one (Hermit) on Jul 22, 2010 at 02:39 UTC

    The closest thing I can think of would be to run your script (or a wrapper) as a cron job (Unix/Linux)or a scheduled task (Windows) and have it take whatever action you want if conditions are met (i.e. if a file has been modified in the last hour or whatever you would look for).

    Not instant, but you can have it run fairly frequently. Might work for you, depending on exactly what your application is.

Re: Trigger the execution!
by matrixmadhan (Beadle) on Jul 22, 2010 at 02:44 UTC
    DirectoryListeners which will take care of whether files have been added, modified, deleted. Based on that tie the action of executing your perl script if the something happens to the config file that you are interested.
Re: Trigger the execution!
by JSchmitz (Canon) on Jul 22, 2010 at 14:32 UTC
    trigger the execution! "CORN job"..This is almost as good as "All of your base belong to us"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://850750]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2017-07-22 13:49 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (339 votes). Check out past polls.