#!/bin/ksh
###############################################################################
#  File Name:     recycle_archivelog.sh
#
#  Usage:        Run it once an hour on the remote machine from crontab
#
#  Description:  Compresses the uncompressed archive log files (except for the 
#                newest one - the file transfer may not have been completed)
#                Removes archive logs older than the retention period
#                Alerts sysadmin, when the free space in the archive filesystem
#                drops under the threshold 
###############################################################################  
#
retention_per=14
arch_dir=/oracle/SID/saparch
fs=/oracle/SID
threshold=90
#
# Compress all the archive logs but the newest (it may not be complete)
#
newnum=`ls -lt $arch_dir/*.dbf|wc -l`
if [ $newnum -gt 1 ]; then
	newest=`ls -lt $arch_dir/*.dbf|head -2|tail -1|awk '{print $9}'`
        find $arch_dir -name "*.dbf" ! -newer $newest -exec compress {} \; 
fi
#
# Remove the archive logs older then retention_per
#
find $arch_dir -name "*.dbf.Z" -mtime +$retention_per -exec rm -f {} \;
#
# Alert sysadmin, if the free space drops under the threshold
#
used_perc=`bdf|grep $fs|grep -v $fs/|awk '{print $5}'|awk -F\% '{print $1}'` 
if [ $used_perc -gt $threshold ]; then
# Run your own paging scripts here
fi