Hi there,
I'm trying to find files that are greater then 30 days old, zip them and move to a different directory. I'm encountering an issue passing a variable (FilesToFind) to name within the find command. Here's the code I'm running:
#! /usr/bin/sh
FileDir=/home/ariba
ZippedDir=/home/ariba/data/archive
FilesToFind="*.dat"
ListOfFiles=`find . -mtime +30 -type f -name \${FilesToFind}`
for i in $ListOfFiles
do
gzip $i
ZippedFile="${i}.gz"
mv $ZippedFile $ZippedDir
done
If there's only 1 file retrieved on the find, the code works. If there's more then one file, I get the following error message:
find: missing conjunction
If I hard code "*.dat" in the find statement, then it works correctly for multiple files, as so:
ListOfFiles=`find . -mtime +30 -type f -name "*.dat"`
So theoretically it seems like I should be able to pass "*.dat" to FilesToFind and it would work. So I've also tried the following, that don't give an error message, but also don't work. No files are retrieved:
FilesToFind="\"*.dat\""
ListOfFiles=`find . -mtime +30 -type f -name ${FilesToFind}`
ListOfFiles=`find . -mtime +30 -type f -name \"${FilesToFind}\"`
I've done a search through the forum, but can't find anything that covers this. I need to be able to use a variable for name vs hard coding it to "*.dat". This is a simplistic version of the code and that value is actually going to be variable. Any suggestions on what I'm doing wrong?
Thanks,
Les...