#!/bin/bash
#
# Oneshot logrotate to compress existing huge files
# This should save situation when system is crashing very fast
# (logrotate from cron job may not help in this case)
#
# Copyright (c) 2016 by Cisco Systems, Inc.
# All rights reserved.
#
fretta_restart_log_files="fia_driver_restart.log fib_mgr_restart.log bma_restart.log bme_restart.log"
for f in ${fretta_restart_log_files} ; do
    if [ -f /var/log/${f} ] ; then
        if [ -f /var/log/${f}.gz ] ; then
            /bin/mv -f /var/log/${f}.gz /var/log/${f}.1.gz
            /usr/bin/logger "moved /var/log/${f}.gz to /var/log/${f}.1.gz"
        fi
        /bin/gzip -c /var/log/${f} > /tmp/${f}.gz
        /bin/rm -f   /var/log/${f}
        /bin/mv      /tmp/${f}.gz /var/log
        /usr/bin/logger "compressed /var/log/${f}"
    fi
done
/usr/bin/logrotate /etc/logrotate.conf > /dev/null 2>&1
