#!/bin/csh -f #(ie run the cshell on this but don't read the .cshrc) # version = 1.01 of waitforchange 1995 Dec 20 # waitforchange: wait for change in file $1 at intervals of $2 seconds # Tom Schneider # National Cancer Institute # Laboratory of Mathematical Biology # Frederick, Maryland 21702-1201 # toms@ncifcrf.gov # http://www-lmmb.ncifcrf.gov/~toms/ # The waitforchange script waits for a file to change and then completes. This # allows one to write parallel processes on any machine, waiting on the results # of previous computations. Since the scripts can run on several machines # looking at a common set of files, it also would create multi-machine # processes. I have not tried this yet, it may have problems with disk # sync'ing. # # see the atchange script for a use of waitforchange. # see the cleanwait to cleanup files left in /tmp when this routine is killed. # see tomdate for the date mechanism used. if ($#argv == 2) then set date = `tomdate` set tmp0 = /tmp/waitforchange0.$date.`whoami`.lockfile while (-f $tmp0) sleep 1 end echo tmp0 > $tmp0 set tmp1 = /tmp/waitforchange1.$date.`whoami`.oldlength set tmp2 = /tmp/waitforchange2.$date.`whoami`.newlength set tmp3 = /tmp/waitforchange3.$date.`whoami`.oldfile cp $1 $tmp3 # set theold = `ls -lL $1| cat` set theold = `ls -lL $1` echo $theold > $tmp1 cp $tmp1 $tmp2 set nochangesize = 0 set nodiff = 0 while (($nochangesize == 0) && ($nodiff == 0)) set nochangesize = `diff $tmp1 $tmp2 | wc -l | sed -e "s/ //"` set thenew = `ls -lL $1` echo $thenew > $tmp2 # now do the more serious diff test since that failed set nodiff = `diff $tmp3 $1 | wc -l | sed -e "s/ //"` if (($nochangesize == 0) && ($nodiff == 0)) then sleep $2 endif end rm -f $tmp0 $tmp1 $tmp2 $tmp3 else echo usage: waitforchange of_file_to_watch sleep_in_seconds endif # generally we should wait a moment to allow the completion of the file. # Perhaps there is a better way to look at the system and # see if any programs have the file still open? set sleeptime = 2 echo -n safety sleep for $sleeptime seconds ... sleep $sleeptime echo done