Compress 30 Days old log files

#!/bin/bash
# Script for compress 30 Days old log files


# As a input provide location where log file present
# Create blank error log file
touch /tmp/feenixdv_error
echo " " /tmp/feenixdv_error
echo -e "Enter log path:-"
read log_Location
echo -e "Log location is :- $log_Location"
# Select 30 days old log file
find $log_Location -mtime +30 -exec ls {} \; > /tmp/feenixdv
    for i in `cat /tmp/feenixdv`
    do
    echo "Creating zip of :- $i"
    # Create zip
    gzip $i;
        if [ $? -ne 0 ]
        then
        # Put all error in error log file which is coming during zipping
        echo -e "Issue in Ziping with :- $i " >>/tmp/feenixdv_error
        fi
    done
# Check if we have any error log
count=`wc -l /tmp/feenixdv_error | cut -d "/" -f 1`
echo "count:- $count"
#set -x
if [ $count -ne 0 ]
then
echo -e "Error during zipping with bellow Files:- `cat /tmp/feenixdv_error`"
fi

Output:-

image

image

Leave a Reply

Your email address will not be published. Required fields are marked *