0

I'm trying to write a script that echos "success" if it finds .trc files older than 5 days in a directory. However I'm getting a full_path_trace': No such file or directory error even though my directory exists. I don't know what i'm doing wrong.

full_path_trace='/u01/app/oracle/myfolder/trace'
if [[ -n $(find "full_path_trace" -name "*.trc" -mtime +5) ]]
 then
   echo "success!"
else

  echo "fail"
fi
1
  • You define full_path_trace but you don't use it. You need a $ between the first double quote and full_path_trace
    – Anthon
    Commented Feb 2, 2016 at 16:15

1 Answer 1

4

You're missing the a $ in front of the variable. Here, I'd do:

if find "$full_path_trace" -name '*.trc' -mtime +5 -print -quit |
   grep -q '^'; then
  echo 'Success!'
else
  echo >&2 fail
fi

Drop the -quit if your find doesn't support it.

grep -q returns true as soon as a line is found in the input.

-quit would cause find to exit upon the first match and stop searching for more. Without -quit, grep would quit after reading the first line and would eventually cause find to exit early if there are a lot of other files.

0

You must log in to answer this question.

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