chazhs
asked on
detect timestamp change and then execute a script
I have a cron job(a perl program) that I need to run only when the timestamp of a particular file changes.
Could anyone help with this?
Thanks.
Could anyone help with this?
Thanks.
what part do you need help with...the timestamp valuation, the monitoring, the execution?
ASKER
The timestamp valuation.
I have developed the program that does the work I need. Only I need to execute it when a particular file a.txt changes. What I am guessing is that I should set a cronjob(that runs every minute may be) to keep checking whether a.txt time stamp changed. If so, how do I track the change in timestamp info of a.txt?
Thanks very much.
I have developed the program that does the work I need. Only I need to execute it when a particular file a.txt changes. What I am guessing is that I should set a cronjob(that runs every minute may be) to keep checking whether a.txt time stamp changed. If so, how do I track the change in timestamp info of a.txt?
Thanks very much.
you do it like this:
save this as watch.pl
and run it from cron
#!/usr/bin/perl
#watch.pl
$fileToWatch='funny.pl';
##################
#######this block of coke will make the file for you
#######in which we keep the record of the last modification
#######time in seconds since the epoch
#############
$file='time.dat';
if(-e $file)
{
$lastTime=<FILE>;
}
else
{
open FIRSTTIME, ">$file";
print FIRSTTIME ${[stat $fileToWatch]}[9];
close FIRSTTIME;
}
##################
open TIMER, $file;
$lastTime=<TIMER>;
close TIMER;
$time=${[stat 'funny.pl']}[9];
if($time>$lastTime){
###execute your action here
print "now is the time to take action";
##
open UPDATE, ">$file";
print UPDATE $time;
close UPDATE;
}
else{exit};
hope that helps,
Bob
save this as watch.pl
and run it from cron
#!/usr/bin/perl
#watch.pl
$fileToWatch='funny.pl';
##################
#######this block of coke will make the file for you
#######in which we keep the record of the last modification
#######time in seconds since the epoch
#############
$file='time.dat';
if(-e $file)
{
$lastTime=<FILE>;
}
else
{
open FIRSTTIME, ">$file";
print FIRSTTIME ${[stat $fileToWatch]}[9];
close FIRSTTIME;
}
##################
open TIMER, $file;
$lastTime=<TIMER>;
close TIMER;
$time=${[stat 'funny.pl']}[9];
if($time>$lastTime){
###execute your action here
print "now is the time to take action";
##
open UPDATE, ">$file";
print UPDATE $time;
close UPDATE;
}
else{exit};
hope that helps,
Bob
#######this block of coke will make the file for you
in this block of code...
there is nothing wrong with me, I promise.
in this block of code...
there is nothing wrong with me, I promise.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
how's married life treating you, Droby10?
ASKER
Bebonham, it works perfect!
Thanks much!!!!!
Thanks much!!!!!
glad to help!