Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

detect timestamp change and then execute a script

Posted on 2001-06-11
8
Medium Priority
?
178 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:chazhs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 5

Expert Comment

by:Droby10
ID: 6188378
what part do you need help with...the timestamp valuation, the monitoring, the execution?
0
 

Author Comment

by:chazhs
ID: 6188443
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.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6193274
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
0
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 
LVL 8

Expert Comment

by:bebonham
ID: 6193280
#######this block of coke will make the file for you

in this block of code...

there is nothing wrong with me, I promise.
0
 
LVL 8

Accepted Solution

by:
bebonham earned 200 total points
ID: 6193283
wait, left over magic string...


$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 $fileToWatch]}[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};



there ya go.  use this one please.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6193299
how's married life treating you, Droby10?
0
 

Author Comment

by:chazhs
ID: 6193628
Bebonham, it works perfect!
Thanks much!!!!!
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6195125
glad to help!
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question