Deleting Glassfish old logs

#!/bin/bash


DAYS_TO_KEEP=$((7 * 86400))     # In seconds
LOG_DIR=/var/lib/glassfishv2/domains/domain1/logs
TODAY=$(date +%s)


for FileName in $(ls ${LOG_DIR}/server.log_*)
do
        FileDate=$(stat –printf=%Y ${FileName})


        DateDiff=$((TODAY – FileDate))


        if [ $DateDiff -gt ${DAYS_TO_KEEP} ]
        then
                echo Deleting ${FileName} ${FileDate} ${TODAY} ${DateDiff}
                rm ${FileName}
        fi


done


##END##

Deja un comentario

Tu dirección de correo electrónico no será publicada.