Yikes...it's the topic that won't go away...  :)

Everything is working, just a little too well.  Take a look at the script below...no 
matter how I structure the two snapshot ls files that are compared, they are ALWAYS 
deemed different and so always result in an e-mail notification being sent.  I've 
tried it both with/without the --full-time option, and also with/without the pipe to 
the md5sum function.

Many have suggested using FAM instead, if I don't get this working I may just punt and 
go that route (resulting in a whole new round of questions for you all, of course).

Thanks everyone!

Stuart


-----Original Message-----
From: Anthony E. Greene [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 13, 2003 12:30 PM
To: [EMAIL PROTECTED]
Subject: Re: program to monitor directory changes (new files) and send
e-mail


Douglas, Stuart wrote:
> Ah, important safety tip as that will be the case.
> 
> Since I'm not comfortable implementing technology I don't fully
> understand, would you be so kind as to translate into English each line
> of your script?  I think I get the basic drift of it..."take a snapshot
> of the contents of a directory, take another and compare the two, if
> their different send an e-mail, if their not, start all over again" or
> something like that.  Getting warm?


That is exactly it. For the record, here is a commented version, as I 
would have written it if I were implementing it on my own server:


#!/bin/sh
#
# Notify the admin if a directory's contents has changed.
#

# The directory to monitor.
watchdir='/path/to/ftpdir'

# Who gets notified of changes. This may be a
# comma-delimited list, but no spaces.
recipient='[EMAIL PROTECTED]'

# The file that holds an md5sum of the directory
# listing, as of the last time it was changed.
sumfile='/path/to/sumfile'

## End of settings ##

# Get the previous md5sum of the directory listing.
olddirsum=`cat $sumfile`

# Get the current md5sum of the directory listing. Use the
# --full-time option to avoid errors based on ls changing the
# displayed date format based on the age of the file.
newdirsum=`ls --full-time $watchdir | md5sum`

# Compare the previous md5sum to the current md5sum.
if [ "$newdirsum" != "$olddirsum" ]; then
   # The directory listing changed.
   # Send notification message.
   ls $watchdir | mail -s "Updated dirlist: $watchdir" $recipient

   # Update the summmary file with the current md5sum.
   echo "$newdirsum" > "$sumfile"
fi



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to