[ale] file modification time via shell script

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sat Aug 4 13:44:26 EDT 2007


On Fri 2007-08-03 21:21:41 -0400, Jim Popovitch wrote:

> Thanks for all the replies, here is what I came up with:
>
> --- bof -----
> 1:  #!/bin/bash
> 2:  
> 3:  LOGFILE=/var/mailman/logs/smtp.log
> 4:  LOCKFILE=/var/mailman/locks/mailman-archive-to-rss.lock
> 5:  
> 6:  if [ -e $LOCKFILE ]; then exit; fi
> 7:  
> 8:  touch $LOCKFILE
> 9:  
> 10: NEW=`find $LOGFILE -mmin 1 -print`
> 11: 
> 12: if [ "$NEW" != "" ]; then
> 13:          /usr/local/mailman/bin/mailman-archive-to-rss
> 14: fi
> 15: 
> 16: rm -f $LOCKFILE
> --- eof -----
>
> Assumptions:
>
> - This script runs every minute from cron
> - smtp.log exists
> - userid running script has permission to execute mailman-archive-to-rss
> - userid running script has permission to write $LOCKFILE
>
> Questions:
>
> 1) Should I be concerned about dead time between line 6 and line 7?
>
> 2) Should I be concerned about -mmin on line 10?

How long does mailman-archive-to-rss take to run?  Will it increase as
time goes on?  If it ever takes more than one minute, and a
modification comes in within the minute it is running, that
modification won't be caught by the next run of the script.

you might do better to note the timestamp of the log when you launched
the original run, and to keep track of it that way.  Something like:


LOGFILE=/var/mailman/logs/smtp.log
LOCKFILE=/var/mailman/locks/mailman-archive-to-rss.lock
REFERENCE=/var/mailmain/locks/mailman-archive-to-rss.ref

if [ -e $LOCKFILE ]; then exit; fi

# if there is no reference file, or the logfile is newer than the reference:
if [ ! -e "$REFERENCE" ] || [ "$LOGFILE" -nt "$REFERENCE" ] ; then
   # remember the timestamp of $LOGFILE for future runs:
   touch "$REFERENCE" -r "$LOGFILE"
   /usr/local/mailman/bin/mailman-archive-to-rss
fi
rm -f $LOCKFILE


hth,

        --dkg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 826 bytes
Desc: not available




More information about the Ale mailing list