1

Our outsourced IT service provider runs the following script via cron to clean up Oracle core and trace files. It clearly is not a well-written script, but my question for the Serverfault crowd is whether there is an error or boundary condition that would have it remove other directories, such as these:

/ora/admin/SCRM01P/bdump /ora/admin/SCRM01P/cdump /ora/admin/SCRM01P/pfile /ora/admin/SCRM01P/udump

We recently had these directories deleted on a production system, crashing Oracle. Have a look at this code. Your insight is appreciated, as I am not very good at Korn shell.

#!/usr/bin/ksh 
#This script check the utilization of the location "/ora/admin/SCRM01P" 
#and if this exceeds the threshold which is 75%, then it attemps to remove all of the 
#core dump files which are "core_*" and "cdmp_*" 
#Otherwise, is removes these core dumps that are older than 7 days 
 THRESHOLD=75 
 MTIME=7 
 TOP_DIR=/ora/admin/SCRM01P 
 cd ${TOP_DIR} 
 USED=$(df -k ${TOP_DIR} |tail -1|awk '{print $5}'|grep \%|sed 's/%//') 
 [ ${USED} -gt ${THRESHOLD} ] && MTIME=-1 
 find ${TOP_DIR}/* -mtime +${MTIME} -type d \( -name "core_*" -o -name "cdmp_*" \) 2>/dev/null|while read DIRTOREMOVE 
 do 
        rm -rf $DIRTOREMOVE 
        #Due to a known Soralis issue, the directory may not be removed by the command above 
        rmdir $DIRTOREMOVE >/dev/null 2>&1 
 done 
 find ${TOP_DIR}/* -mtime +${MTIME} -name "*.trc"  -size +2000 2>/dev/null|while read TRACE_FILE 
 do 
        cp /dev/null ${TRACE_FILE} 
 done 
1
  • “Soralis” is a great typo!
    – automaciej
    Jan 14, 2012 at 18:16

2 Answers 2

2

One condition could be if this kind of directory existed (note the space):

/ora/admin/SCRM01P/bdump secondword/core_foo

The while command separates words by white space, so the while loop body would be called two times, once with /ora/admin/SCRM01P/bdump and once with secondword/core_foo.

1
  • Thanks. I suspect this is what happened, though without knowing the original list of files that were deleted, it's tough to confirm. We disabled the script and it has been re-written, with logging and sanity checking before a file or directory is deleted.
    – Dave
    Jan 20, 2012 at 21:27
2

You can test this yourself. change the

    rm -rf $DIRTOREMOVE 
    #Due to a known Soralis issue, the directory may not be removed by the command above 
    rmdir $DIRTOREMOVE >/dev/null 2>&1 

to

echo "Deleting $DIRTOREMOVE"

and then change

cp /dev/null ${TRACE_FILE}

to

echo "Truncating ${TRACE_FILE}"

Which should show you what is being worked on.

1
  • Thanks. Logging what has been deleted should be in all housekeeping scripts. It's now been added to the specific script in this post and a fleet-wide review is underway so assess every script against a quality standard.
    – Dave
    Jan 20, 2012 at 21:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .