On Mon, Mar 17, 2003 at 08:35:57AM -0500, Douglas, Stuart wrote: > 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 >
Doug - Remove everything after the #Compare ... line in your script and replace it with the following. You need the if...then block. ---------------- # Compare the previous md5sum to the current md5sum. if [ "$newdirsum" != "$olddirsum" ]; then # Get the process ID and scriptname and use them to # generate a tempfile name. This method is not guaranteed # unique, but it should be Good Enough. pid=$$ scriptname=$(basename $0) mailfile=/tmp/$scriptname.mailfile.$pid # Check each file in $watchdir to see if it was created or changed # since the last md5sum was generated. for file in $(ls $watchdir); do if [ $file -nt $sumfile ]; then ls --full-time $file >> $mailfile ## Now mail a notification message to the recipients list ## mail -s 'New voicemail message detected' $recipient < $mailfile ## then delete mailfile rm $mailfile fi done fi # Finally, update the summary file with # the current md5sum echo "$newdirsum" > "$sumfile" -- Jack Bowling mailto: [EMAIL PROTECTED] -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://listman.redhat.com/mailman/listinfo/redhat-list