Home » Infrastructure » Linux » Delete files using shell scripts.
Delete files using shell scripts. [message #257396] Wed, 08 August 2007 04:37 Go to next message
gln.sarma
Messages: 11
Registered: April 2004
Location: hyderabad`
Junior Member

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 #257515 is a reply to message #257396] Wed, 08 August 2007 09:18 Go to previous messageGo to next message
BlackSwan
Messages: 22728
Registered: January 2009
Senior Member
>We are required to write a shell script that the daily folder should contain only 30.
Does the 30 include "." and/or ".."; which always exist?
Re: Delete files using shell scripts. [message #257563 is a reply to message #257396] Wed, 08 August 2007 11:49 Go to previous message
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
Previous Topic: execute commands in Linux platform
Next Topic: Unable to boot OEL / RHEL 4 - problem with Grub
Goto Forum:
  


Current Time: Tue Sep 02 19:14:41 CDT 2014

Total time taken to generate the page: 0.39365 seconds