#!/bin/sh . /usr/local/etc/dropbox.conf sleep 2 date=`date -v -5M "+%Y%m%d%H%M"` mtime_date=`date -v -5M "+%s"` logfile="${dropbox_log_dir}/access.log.${date}" echo $date if [ -e ${logfile} ]; then echo "open ${logfile}" # get the last-modified time of the logfile, needed to delete leaked logfile which can happen during downtime mtime_date=`stat -t "%s" -f "%m" ${logfile}` # get lines that match the form "///- 200" for tag in `cut -d ' ' -f1,2 ${logfile} | grep '^/[a-z0-9]\+/[a-z0-9]\+/-[0-9]\+ 200\$'|cut -d ' ' -f1`; do # devide the match at "-", first part is link to mailbox, second is the response-size delivered for the request echo "Working on tag ${tag}" link=${tag%%/-*} size=${tag##*-} # check if the link to mailbox exists, otherwise set the size to 0 to prevent wierd things if [ -e ${dropbox_mail_dir}/${link} ]; then echo -n " ${dropbox_mail_dir}/${link} -> " mailbox=`stat -f "%Y" ${dropbox_mail_dir}/${link}` echo ${mailbox} else size='0' fi # if the size of the response is larger than 0 (a mail was delivered), delete the mailbox if [ "${size}" != "0" ]; then echo " remove mailbox ${mailbox} (size: ${size})" rm -rf ${mailbox} echo " remove link ${dropbox_mail_dir}/${link}" rm -rf ${dropbox_mail_dir}/${link} else echo " mailbox is empty" fi done fi rm -f ${logfile} # find all leaked access logs echo " Check for leaked logfiles" for leak_logfile in `find ${dropbox_log_dir} -name 'access.log.*'`; do # get the last-modified time of the logfile in question mtime=`stat -t "%s" -f "%m" ${leak_logfile}` echo -n " ${leak_logfile} " if [ ${mtime} -le ${mtime_date} ]; then echo "leaked, deleted" rm -f ${leak_logfile} else echo "okay" fi done