Operating System - HP-UX
1849261 Members
5699 Online
104042 Solutions
New Discussion

Re: Script to clear archive log

 
SOLVED
Go to solution
ckchai
Frequent Advisor

Script to clear archive log

Hi,

Currently Im running the backup of archive log using tar.

After that manually remove the archive log files.

Does anyone have a script to automatic tar the archive log, after that capture the files that been backup and remove it?

3 REPLIES 3
saju_2
Respected Contributor
Solution

Re: Script to clear archive log

Hi

Try the below script.. Modify the file names and locations accroding to your env.

cd /archdir/
ls -lrt |awk '{print $9}'>>/tmp/archivelogout.`date`
tar -cvf /tmp/archvlog.`date`.tar *
for i in `cat /tmp/archivelogout.`date`
do
tar -tvf /tmp/archvlog.`date`.tar|awk '{print $8}'|grep $i
logs=`echo $?`
if [ $logs -eq 0 ]
then
rm /archdir/$i
else
echo "$i not backed up">>/tmp/notbackedfile.`date`
fi
done


Pls do not try this script directly as this involvs a "rm" command. !!!! :)


Regards
CS

saju_2
Respected Contributor

Re: Script to clear archive log

Hi

Try the below script.. Modify the file names and locations accroding to your env.

cd /archdir/
ls -lrt |awk '{print $9}'>>/tmp/archivelogout.`date`
tar -cvf /tmp/archvlog.`date`.tar *
for i in `cat /tmp/archivelogout.`date`
do
tar -tvf /tmp/archvlog.`date`.tar|awk '{print $8}'|grep $i
logs=`echo $?`
if [ $logs -eq 0 ]
then
rm /archdir/$i
else
echo "$i not backed up">>/tmp/notbackedfile.`date`
fi
done


Pls do not try to run this without testing as it contains a "rm" command. !!!! :)


Regards
CS

Muthukumar_5
Honored Contributor

Re: Script to clear archive log

Try as,

#!/bin/ksh
# User input -- Here
ARCHIVEDIR=/tmp/arcive

cd ${ARCHIVEDIR}
tar -cvf /archive_$(date +%d%m%y).tar *
if [[ ${?} -eq 0 ]]
then
echo "Archive of ${ARCHIVEDIR} is successful - $(date)"
rm -f *
else
echo "Archive of ${ARCHIVEDIR} is failure - $(date)"
# echo "Archive ttempt again" | mailx -s "Failure" mail ID
fi
# END
exit 0

Archive file will be in the format as, /archive_DDMMYY.tar file.

hth.
Easy to suggest when don't know about the problem!