Aipo7でユーザーごとのWebメール容量をCSV出力する

#!/bin/sh

AIPO_DBHOST=localhost
AIPO_DBUSER=aipo_postgres
AIPO_DBNAME=org001
AIPO_MAILDIR=/usr/local/aipo/tomcat/webapps/aipo/WEB-INF/mail/org001

WORKDIR=/tmp/analyze_webmail

if [ ! -d ${WORKDIR} ]; then
  mkdir ${WORKDIR}
fi

psql -q -h${AIPO_DBHOST} -U${AIPO_DBUSER} -d${AIPO_DBNAME} -c "SELECT EIP_M_MAIL_ACCOUNT.user_id,EIP_M_MAIL_ACCOUNT.account_id,TURBINE_USER.login_name,TURBINE_USER.disabled,EIP_M_MAIL_ACCOUNT.mail_address FROM EIP_M_MAIL_ACCOUNT INNER JOIN TURBINE_USER ON EIP_M_MAIL_ACCOUNT.user_id = TURBINE_USER.user_id ORDER BY user_id ASC;" | grep @ | sed -e "s/ *//g" | sed -e "s/^\([0-9]\+\)|/\1\//" > ${WORKDIR}/accountlist.txt

echo -n "" > ${WORKDIR}/result.csv
for DIR in `find ${AIPO_MAILDIR} -maxdepth 2 -type d | sed -e "s|${AIPO_MAILDIR}||g" | sed -e "s|^/||g" | grep "/" | sort -n`; do
  SIZE=`du -sh ${AIPO_MAILDIR}/${DIR} | awk -F' ' '{print $1}'`
  if [ `egrep "^${DIR}\|" ${WORKDIR}/accountlist.txt | wc -l` -eq 0 ]; then
    echo ${SIZE},${DIR},,, >> ${WORKDIR}/result.csv
  else
    EXTRA=`egrep "^${DIR}\|" ${WORKDIR}/accountlist.txt | sed -e "s/|/,/g"`
    echo ${SIZE},${EXTRA} >> ${WORKDIR}/result.csv
  fi
done

実行後、/tmp/analyze_webmail/result.csvに結果が出力されます