You are on page 1of 2

AUTO ZIP LOG FILES IN UNIX SERVERS

#!/bin/bash
#*********************************************************************
#* Author
: Venkata Suman
#* Purpose
: Auto zip log files in UNIX SERVERS
#* Date
: 20-03-2014
*
#*********************************************************************
#

*
*

############### User Defined Parameters


Here
FS :- Indicates Filesystem
#############
FS=/logs
HWM & LWM :- If the Filesystem
PC=`df -k ${FS}|awk -F" " '{print $5}'|tr -d "%"|tail
utilization reached above 80% , Then it
-1 `
will zip files upto 70%
HWM=80
LOG_PATH :- where log files need to
LWM=70
store.
day=`date | awk '{print $3}'`
month=`date | awk '{print $2}'`
file=`ls -t ${FS}/test* :- file name
year=`date | awk '{print $6}'`
which you want to zip
time=`date | awk '{print $4}'|cut -f1,2 -d :`
MAILTO :- Whom you need to send mail
LOG_PATH=/logs
LOGFILE=$LOG_PATH/ZIP-LOGFILES_$day$month$year.log
MAILTO="GMIN-EPLUS-BRIDGE-OSSupport@atos.net"
#################################################

echo " ======== Auto zip log files : `date|awk '{print $3 $2 ,$4}'`========">> $
{LOGFILE}
if [ $PC -gt $HWM ];then
echo "$FS is ${PC}% full ... proceeding to delete old archive log files .,. "
>>/tmp/autoclean.tmp
while [ $PC -gt $LWM ];do
file=`ls -t ${FS}/test* | tail -1`
echo " Auto zip log files ...`ls -l $file|awk '{print $6 ,$7 ,$8 ,$9 "[Size:",$5 "]"}'`" |tee -a
/tmp/autoclean.tmp >>${LOGFILE}
echo " Auto zip log files ...`ls -l $file|awk '{print $6 ,$7 ,$8 ,$9 "[Size:",$5 "]"}'`"
cp $file /tmp
gzip /tmp/test*
rm $file
cp /tmp/test*.gz ${FS}/
rm /tmp/test*.gz
sleep 1
echo " ............ zip log files " >> ${LOGFILE}
PC=`df -k ${FS}|awk -F" " '{print $5}'|tr -d "%"|tail -1 `
done
echo " $FS is ${PC}% full now. " >>/tmp/autoclean.tmp
cat /tmp/autoclean.tmp|mailx -s "Core files deleted ..." ${MAILTO}
rm /tmp/autoclean.tmp

AUTO ZIP LOG FILES IN UNIX SERVERS


else
echo " No Files to Delete " >> ${LOGFILE}
fi

You might also like