SHELL SCRIPT TO DELETE ARCHIVELOG FROM DISK

This shell script can be used to blindly delete archive logs from disk in a test or development database in case FRA gets full frequently. Warning: Do not use this in production due to recovery reasons. I use this script because of short of storage to accommodate huge archive logs generated due to DML in disk during testing.

#!/bin/bash

trap 'rm -rf /home/oracle/archdel.log' EXIT
#For logging purpose
_LOG_0()
{
echo "*************************************$1"
}

#Set the environment variables
_SET_ENV_1()
{
export ORACLE_SID=x3z6zx9
export ORACLE_HOME=/apps01/base/product/11.2.0/dbhome_1
export PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin:/apps01/base/product/11.2.0/dbhome_1/bin
}

_DELARCH_2(){
$ORACLE_HOME/bin/rman << EOF
connect target /
crosscheck archivelog all;
delete noprompt archivelog all;
exit;
EOF
}

_TOTARCH_3(){
echo "TOTAL ARCHIVE LOGS DELETED IN LAST 5 MINS:`grep 'objects' /home/oracle/archdel.log|awk '{print $2}'|awk '{SUM+=$1;}END{print SUM;}'`"
}

_SET_ENV_1
_DELARCH_2
_TOTARCH_3

Set this in crontab

[oracle@x3dbzx36 ~]$ crontab -l
*/5 * * * * /home/oracle/archdel.sh > /home/oracle/archdel.log

Leave a Reply