Solaris 8 – 目录不见了; 这是清理脚本的罪魁祸首?

我们的外包IT服务提供商通过cron运行以下脚本来清理Oracle核心和跟踪文件。 这显然不是一个写得很好的脚本,但是对于Serverfault人群来说,我的问题是,是否有错误或边界条件会删除其他目录,例如:

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

我们最近在生产系统上删除了这些目录,导致Oracle崩溃。 看看这个代码。 你的洞察力是值得赞赏的,因为我不太擅长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 

一种情况可能是如果这种types的目录存在(注意空间):

 /ora/admin/SCRM01P/bdump secondword/core_foo 

while命令通过空格分隔单词,因此while循环体将被调用两次,一次使用/ora/admin/SCRM01P/bdump ,一次使用secondword/core_foo

你可以自己testing一下。 改变

  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 

 echo "Deleting $DIRTOREMOVE" 

然后改变

 cp /dev/null ${TRACE_FILE} 

 echo "Truncating ${TRACE_FILE}" 

哪个应该告诉你正在做什么。