Delete files using shell scripts. [message #257396] |
Wed, 08 August 2007 04:37 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
gln.sarma
Messages: 11 Registered: April 2004 Location: hyderabad`
|
Junior Member |
![gln_gln_482003](/forum/theme/orafaq/images/yahoo.png)
|
|
Oracle : 10g
os : Linux
We are using backup strategy. Daily, weekly, Monthly bacups for dmp files.
We want to purge the gz file which are generated by dmp export command.
Till now we are using a shell script which can delete depending on the date critria
in the daily folder
/bin/rm -f `find /home/backup/daily/Jul2007/DB/conrep_*.gx -mtime +30 -ls -prune|awk '{print $11}'`
method.
This is not appropriate for the requirement
We are required to write a shell script that the daily folder should contain only 30.
ie critiria is not date it is count of No files.
How to do this ?
Help in solving this
|
|
|
|
Re: Delete files using shell scripts. [message #257563 is a reply to message #257396] |
Wed, 08 August 2007 11:49 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
DreamzZ
Messages: 1666 Registered: May 2007 Location: Dreamzland
|
Senior Member |
|
|
some thing like this.Edit it according your requirments.
#!/bin/ksh -x
. $HOME/.profile_mydb
STATS_LOG_DIR=$STATS_HOME_DIR/log
DATE=`date +%Y%m%d%H%M`
STATS_LOG=$STATS_LOG_DIR/stats_dell_pull.log.$DATE
STATS_SQLPLUS_LOG=$STATS_LOG_DIR/stats.SQLPLUS_dell_pull.log.$DATE
DEL_LOG=/tmp/${ORACLE_SID}_DAILYLOGS_DELL_PULL.del;
DAILYLOGS=/tmp/${ORACLE_SID}_DAILYLOGS_DELL_PULL;
ERROR_FLG='0'
# List the Log Files in the Decending Order of Creation Time
ls -t ${STATS_LOG_DIR} > ${DAILYLOGS}
print "Starting Time : `date` \n" >> $DEL_LOG
count=0
# Starting the Loop for Deletion, Leaving the Latest 40 Arc.Files
unalias rm
for i in `cat ${DAILYLOGS}`
do
count=`expr ${count} + 1`
if (( ${count} > 10 )); then
echo "Deleting ${count}; ${STATS_LOG_DIR}/${i}\n" >> $DEL_LOG
rm ${STATS_LOG_DIR}/${i}
fi
done
|
|
|