bash检查核心存在并且是最近的

时间:2012-09-15 23:48:56

标签: bash find

我正在寻找一种更简单的方法:

#!/usr/bin/bash

FILE=core
DAYS=1

cd /programdir

if [ -f ${FILE} ]; then
   agetest=$(find . -name "${FILE}" -type f -mtime +${DAYS} -print | wc -c)
   if [[ agetest -eq 0 ]] ; then
      echo "$FILE exists and is not older than ${DAYS} days."
   fi
fi

如果脚本找到核心文件且核心文件是最近的(1天内),我想处理核心文件(使用dbx命令)。所以我会运行一个dbx命令,其中echo语句是。似乎应该有一种方法以1 if语句以更优雅的方式执行此操作,但我无法想到如何做到这一点。有什么想法吗?

我知道用tmpwatch或find / rm清理旧的核心文件会更容易,但我不允许这样做。

1 个答案:

答案 0 :(得分:0)

#!/usr/bin/bash

FILE=core
DAYS=1

if [ `find /programdir -name "${FILE}" -type f -mtime +${DAYS}` ]; then
  echo "$FILE exists and is not older than ${DAYS} days."
fi