find command in shell script

Hi,
dirs.conf fine contains below data

/a/b/c/dir1|50
/a/b/c/dir2|50
/a/b/c/dir3|50

In a shell script I do as below

while read file_rec
do
        dir_name=`echo "${file_rec}" | cut -d "|" -f 1`
        purge_days=`echo "${file_rec}" | cut -d "|" -f 2`

        if [ -d $dir_name ]
        then
        echo "#### The purge days for the directory ${dir_name} is ${purge_days} ####" >> $log
        # To list files with the format YY-MM-DD
	find ${dir_name} -type f -name \"*[1-2][09][0-9][0-9]-[01][0-9]-[0-3][0-9]*\" -mtime +${purge_days} -exec ls -ltr {} \\; >> $log
        else
        echo "*** The directory $dir_name does not exists ***" >> $log
        fi
        dir_name=""
        purge_days=""
done < dirs.conf

My problem is, the find command is not running and listing the old files in log file

Can someone help...

Regards,

You dont need to call external commands to split strings. Either use parameter expansion:

dir_name=${file_rec%|*}
purge_days=${file_rec#*|}

Or use multiple variables in your read command:

IFS='|' read dir_name purge_days

Quote your variable references:

  if [ -d "$dir_name" ]

Don't escape the quotes or the backslash:

find "$dir_name" -type f -name "*[1-2][09][0-9][0-9]-[01][0-9]-[0-3][0-9]*" \
                                -mtime +"$purge_days" -exec ls -ltr {} \; >> $log

The -t and -r options to ls will not do anything as you are giving ls a single filename

Two things: a) if you run this with set -x does it appear to interpolate all of your variables correctly?; and, b) if it does, and you take this same interpolated find query and run it manually, does it work then?

I also notice the extra ;-char at the end of the find query. Why do you need to include this? The find shouldn't need additional prompting.

Thanks Johnson the double quote substitution worked.