我们的外包 IT 服务提供商通过 cron 运行以下脚本来清理 Oracle 核心和跟踪文件。这显然不是一个写得很好的脚本,但我对 Serverfault 的问题是,是否存在错误或边界条件会导致它删除其他目录,例如这些:
/ora/管理员/SCRM01P/bdump /ora/管理员/SCRM01P/cdump /ora/管理员/SCRM01P/pfile /ora/管理员/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
答案1
一种情况是如果这种目录存在(注意空格):
/ora/admin/SCRM01P/bdump secondword/core_foo
该while
命令用空格分隔单词,因此 while 循环体将被调用两次,一次使用/ora/admin/SCRM01P/bdump
,一次使用secondword/core_foo
。
答案2
您可以自己测试一下。更改
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}"
它应该会向您展示正在进行的工作。