Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Trigger the execution!

by tart (Beadle)
on Jul 22, 2010 at 01:22 UTC ( [id://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 script.pl) 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 (script.pl) to run
Any ideas?
Cheers,
tart

Updates:

JavaFan,
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,
tart

update
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(script.pl); # 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 (Curate) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://850750]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found