Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove files within a unix shell script

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
0
0
ZA
Afternoon,

Iam currently running a oracle datapump through a unix shell script.
The problem i have is that the dmp files have increased over time to more or less 25 dmp files perday BUT are not deleted daily. It deletes only the first 22 files leaving the other two or three in the set directory.
HOW CAN I DELETE ALL FILES WITHIN DIRECTORY
herewith my removing of files command within my unix script
Code:
 if [ -r ${EXPORTDIR}/${i}.dmp ]; then
           rm ${EXPORTDIR}/${i}.dmp
 fi

herwith example of files not deleted from directory
Code:
rw-r-----   1 oracle   oinstall 1060347904 Nov  7 01:59 /u8/datapump/MAC/MAC20.dmp
-rw-r-----   1 oracle   oinstall 1605095424 Nov  7 01:59 /u8/datapump/MAC/MAC21.dmp
-rw-r-----   1 oracle   oinstall 898039808 Nov  7 01:59 /u8/datapump/MAC/MAC22.dmp
-rw-r-----   1 oracle   oinstall 166653952 Nov  6 01:54 /u8/datapump/MAC/MAC23.dmp
-rw-r-----   1 oracle   oinstall 36659200 Nov  6 01:54 /u8/datapump/MAC/MAC24.dmp

Any assistance will be highly appreciated
 
HOW CAN I DELETE ALL FILES WITHIN DIRECTORY
rm -f ${EXPORTDIR}/*.dmp

BTW, what is the value of ${i} ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The Value of ${i} belongs in the Oracle parfile, because i need the create statements for Db recovery so i do a export as well as a import into a SQL file
herewith what it looks like
Code:
create_exp_parfile()
{
        echo "USERID=system/${SYSTEM_001P}" > ${EXP_PARFILE}
        echo "DIRECTORY=datapump_mac" >> ${EXP_PARFILE}
        echo "VERSION=LATEST" >> ${EXP_PARFILE}
        [b]echo "DUMPFILE=MAC%U.dmp" >> ${EXP_PARFILE}[/b]
        echo "PARALLEL=16" >> ${EXP_PARFILE}
        echo "LOGFILE=MAC.log" >> ${EXP_PARFILE}
        echo "METRICS=y" >> ${EXP_PARFILE}
        echo "CONTENT=all" >> ${EXP_PARFILE}
        echo "SCHEMAS=MAC" >> ${EXP_PARFILE}
        echo "JOB_NAME=EXP_MAC_`/usr/bin/date '+%d%m%Y'`" >> ${EXP_PARFILE}
        echo "FILESIZE=6G" >> ${EXP_PARFILE}
        echo "REUSE_DUMPFILES=y" >> ${EXP_PARFILE}
}
the import parfile :
Code:
create_imp_parfile()
{
        echo "USERID=system/${SYSTEM_001P}" > ${IMP_PARFILE}
        echo "DIRECTORY=datapump_mac" >> ${IMP_PARFILE}
        [b]echo "DUMPFILE=${i}%U.dmp" >> ${IMP_PARFILE}[/b]
        echo "LOGFILE=IMP.log" >> ${IMP_PARFILE}
        echo "SQLFILE=MAC.sql" >> ${IMP_PARFILE}
        echo "FULL=y"  >> ${IMP_PARFILE}
        echo "JOB_NAME=IMP_MAC_`/usr/bin/date '+%d%m%Y'`" >> ${IMP_PARFILE}
}
WILL the rm -f ${EXPORTDIR}/*.dmp
still work in this case?
 
I changed the script to include the following:
Code:
do_export()
{
        if [ -r ${EXPORTDIR}/${i}.dmp ]; then
           rm -f ${EXPORTDIR}/*.dmp
        fi
BUT TO NO AVAIL YOUR ASSISTANCE WILL BE HIGHLY APPRECIATEd

The out put directory still has the old files
Code:
-rw-r-----   1 oracle   oinstall 6442450944 Jan 11 00:09 /u8/datapump/MAC/MAC17.dmp
-rw-r-----   1 oracle   oinstall 2024898560 Jan 11 00:17 /u8/datapump/MAC/MAC18.dmp
-rw-r-----   1 oracle   oinstall 582565888 Jan 11 00:17 /u8/datapump/MAC/MAC19.dmp
-rw-r-----   1 oracle   oinstall 1042161664 Jan 11 00:17 /u8/datapump/MAC/MAC20.dmp
-rw-r-----   1 oracle   oinstall 88600576 Jan 11 00:17 /u8/datapump/MAC/MAC21.dmp
-rw-r-----   1 oracle   oinstall 2822144 Jan 10 00:09 /u8/datapump/MAC/MAC22.dmp
-rw-r-----   1 oracle   oinstall 42049536 Jan  7 00:09 /u8/datapump/MAC/MAC23.dmp
-rw-r-----   1 oracle   oinstall 56913920 Dec 24 23:58 /u8/datapump/MAC/MAC24.dmp
 
Code:
do_export()
{
        rm -f ${EXPORTDIR}/*.dmp

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Should i leave out ?
Code:
if [ -r ${EXPORTDIR}/${i}.dmp ]; then

Because that is exactly the rm command i currently have in my script
 
Yes, leave it out

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top