(GNU) find -mtime using variables

1.5k Views Asked by At

I'm trying to find files using -mtime +(variable), but everytime I execute below in GNU I'm getting an error:

find: missing argument to `-mtime'

Tried in AIX and it worked.

#------config-------#
cat hkeep.cfg
#<Directory to be purge>,<Days to Purge>
/home/fbmadm/logs,15

#------MAIN-------#
for line in `cat hkeep.cfg | grep -v "#"`;do
hkDir=`echo $line | awk -F"," '{print $1}'`
hkCnt=`echo $line | awk -F"," '{print $2}'` 

find $hkDir -mtime +$hkCnt
done
1

There are 1 best solutions below

1
On

Adding an echo line may help you figure out the problem:

for line in `cat hkeep.cfg | grep -v "#"`;do
hkDir=`echo $line | awk -F"," '{print $1}'`
hkCnt=`echo $line | awk -F"," '{print $2}'` 
echo find $hkDir -mtime +$hkCnt
find $hkDir -mtime +$hkCnt