Simple activity report from FTP xferlog

UPDATE: I found that what I originally posted was wrong and didn’t work at all. I don’t know how I managed to do that, but I’ve fixed it and it’s verified as working now.

I was asked if there was a way to extract the FTP activity to be emailed to someone. The server had a typical xferlog, but the box was being used for shared hosting and the reports didn’t need to include results for all of the other sites.

I put together the following script to extract the activity and transpose it to a more friendlier output. Continue reading

Remove old messages from Plesk/Qmail Maildir mailboxes

I needed to remove messages older than a week old for a list of email accounts on a Plesk system running Qmail. I put together the following BASH script to locate the messages using find and back them up outside of the mailbox (just in case). This builds on the technique I used in my previous post, Maintain directory structure copying `find` results.

All you need to do is create a file with one address per line to be read in by the command.

cd /var/qmail/mailnames; \
IFS="@"; \ 
while read LINE ; \
do \
    ADDR=( ${LINE} ); \
    echo "${ADDR[0]}@${ADDR[1]}"; \
    find ${ADDR[1]}/${ADDR[0]}/Maildir/ \
        \( -path "*/cur/*" -o -path "*/new/*" \) \
        ! -type d -mtime +7 | \
        while read FILE; \
        do \
            DIR=$( dirname ${FILE} ); \
            mkdir -p /path/to/dst/${DIR}; \
            mv ${FILE} /path/to/dst/${DIR}; \
        done; \
done < /path/to/address_file

Maintain directory structure copying `find` results

Let’s say you have a directory structure consisting of files owned by various users, but you want to copy only the files of a particular user to another path, but maintain the directory structure in the destination path. If you just use something like this…

find /path/to/src/ -user foo -exec cp -a {} /path/to/dst/

…you end up with all of the files in /path/to/dst/ with the original directory structure flattened out.

I came up with the following to solve the problem:

find /path/to/src/ -user foo | while read FILE \
do \
    DIR=$( dirname ${FILE} ); \
    mkdir -p /path/to/dst/${DIR}; \
    cp -d --preserve=mode,ownership,timestamp ${FILE} /path/to/dst/${DIR}; \

Here’s a brief explanation. Since the find command returns the relative path of the matching item in it’s STDOUT, we can use the dirname command to get the original relative directory name. We then create the directory if it doesn’t exist, and finally do the copy.

Plesk and RBL checking versus SMTP Authentication

A couple of weeks ago at work, I was arguing which RBLs should be used with Plesk came up. I had always assumed that Plesk’s qmail setup would allow authenticated users regardless of any RBL results. If that were the case, then using wouldn’t pose any problem to mail users on a residential Internet service. I was wrong, but I wanted to sort out why and what options were available. Continue reading