Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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 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!;-)

Comment on Trigger the execution!
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 (Friar) 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 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 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
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? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-08-30 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls