** Reply to message from "Douglas, Stuart" <[EMAIL PROTECTED]> on Fri, 14 Mar 2003 
13:34:47 -0500

> Tony (et al),
> 
> Thanks...haven't tried your additional config yet, still working with the first 
> setup.  I'm hitting a wall trying to get the mail to actually send.  The md5sum is 
> working correctly (updating with changes), but I never get any e-mail.  Ideas?


Hi, Douglas. I got it working last night after some hints from Tony. Here is my 
working version:


----- begin script ----

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

# The directory to monitor.
watchdir='/var/spool/voice/incoming'
#watchdir='/home/jb/Mail/incoming/jbinpg'
#watchdir='/tmp'

# 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='/home/jb/sumfile'

## End of settings ##

## Now we compare old sumfile of watchdir to new sumfile and if different  ##
## overwrite old with new ##

# Get the previous md5sum of the directory listing.
#olddirsum=`cat $sumfile`
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`
newdirsum=$(ls --full-time $watchdir | md5sum)

# 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"

  
------ end script ------

I have it monitoring my dump directory for my voicemail app, VOCP (shameless plug: 
awesomely useful set of perl apps at http://www.vocpsystems.com).  Naturally, it can 
be tailored to watch anything you want.

If you are having trouble, I would suggest commenting out the "rm $mailfile" until you 
know it is being written.

jb



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

Reply via email to