Hi,
I am trying to write a shell script to delete logs generate by db when space in the folder reaches 70%. i am getting space values from db, find the files at OS and remove them by using a cron job runs every 5minutes.
I have to keep the latest 5 files at any time, my problem is that log files are generated based on today date folder eg:
2009_03_20, 2009_03_21, 2009_03_22 etc. and
a log file is generate at 30 time interval gap or may generate 2 files per minute depends upon db activity.
how to keep only latest 5 files and remove rest of the files
my script looks like this in linux env.
#! bin/bash
ORACLE_SID="$1"
limit=$2
if [ $spaceused -gt $limit ]; then
echo "time to delete archivelogs to free up space"
find $fradest/$ORACLE_SID/archivelog -type f -maxdepth 2 -printf "%T@\t%p\n"| sort -k1,1n |cut -f2-|sed '$d'|rm -rf
else
echo "Not required to delete logs.. lots of space"
fi
please advice me, or suggestions to improve my script.
Thanks for the code suggestions, i will try to implement and
need inputs on how to keep latest 5 files all the time while remove all other files from the said folders & sub folders when ever the script runs.