#!/bin/sh

# Rotates server log files, without affecting users who may be
# connected to the server.

# This can be run as a cron script

DATE=`date +%d%h-%I%p`
ROOTDIR=`dirname $0`

# Add here any additional hardcoded logfiles you want rotated.
LOGS='errors secure'
CUSTLOGS=`grep flex-init $ROOTDIR/config/obj.conf \
          | sed -e 's/\\\"//g' -e 's/Init //g' -e 's/\" /\"/g' \
          | awk 'BEGIN { FS = "\""; }  \
                       { n = 0; \
                         while(n++ <= NF) if(index($n, "/") == 1) print $n; }'`

(cd $ROOTDIR/logs;

 for i in $LOGS; do
   if [ -f $i ]; then
     mv $i $i.$DATE
   fi
 done

 for j in $CUSTLOGS; do
   if [ -f $j ]; then
     mv $j $j.$DATE
   fi
 done
)

$ROOTDIR/restart
