Log Rotation Script For Adempire Nohup.Out

From Posibolt Solutions Pvt Ltd
Jump to: navigation, search
  • A shell script to backup a file (nohup.out) & remove if the number of backup file is greater than six.
#!/bin/bash
DATE=`date '+%-d%b%y'`
Adempiere="/home/admin/WaykkCS_Adempiere"   ---------------------- (Adempiere path)
BKUPDIR="$Adempiere/utils     ------------------------------------ (path of backup file)
BKUPFILE="$Adempiere/utils/nohup.out"
if [ [! -f $BKUPFILE] ] ; then
echo $BKUPFILE file is not there. | mailx -s "$Adempiere nohup.out Status" sysadmins@posibolt.com
exit
else
cp $BKUPFILE $BKUPDIR/nohup.out_$DATE       
truncate -s 0 $BKUPFILE   ---------------------------------------- (clear all the contents of the backup file after the above backup)
count=`ls $BKUPDIR/nohup.out_*| wc -l`
if [ $count -gt  6 ]; then    ------------------------------------ (remove the old backup if the no of backup file is greater than six)
cd $BKUPDIR && rm `ls  -1tr nohup.out_* | head -1`     
fi
fi