1844223 Members
3164 Online
110230 Solutions
New Discussion

find hint

 
Jose Mosquera
Honored Contributor

find hint

Hi pals,

Inside a script I am trying to find files using variables, then the command construction seems fine but not run. I have even tried to escape the -exec parsed {} but nothing. Where I am failing?

FILENAME="trartiaur*.txt"
EXPIRATION=60
COMMAND="/usr/contrib/bin/gzip -9"

find . -type f -name $FILENAME -mtime +$EXPIRATION -exec $COMMAND {} \;

Rgds.
8 REPLIES 8
MarkSyder
Honored Contributor

Re: find hint

Do you get an error message?

What happens if you run the find command from the command line?

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Jose Mosquera
Honored Contributor

Re: find hint

Hi,

No error message is displayed, even the $? value is zero.

Rgds.
Peter Godron
Honored Contributor

Re: find hint

Jose,
have you tried:
find . -type f -name "${FILENAME}" -mtime +${EXPIRATION} -exec ${COMMAND} {} \;
Jose Mosquera
Honored Contributor

Re: find hint

Yeap, I've tried!
MarkSyder
Honored Contributor

Re: find hint

Sorry if this is insulting, but is it possible there are no files that meet the criteria?

Mark
The triumph of evil requires only that good men do nothing
Peter Godron
Honored Contributor

Re: find hint

Jose,
on my machine:
#!/usr/bin/sh
FILENAME="*.txt"
EXPIRATION=2
COMMAND="ls -l"
find . -type f -name "${FILENAME}" -mtime +${EXPIRATION} -exec $COMMAND {} \;

$ ./a.sh
-rw-r----- 1 godronpw users 695 May 11 12:29 ./perl.txt
-rw-rw-rw- 1 godronpw users 670 May 11 12:30 ./perl2.txt


Otherwise I can only advise to slowly build up your find i.e. start with find . -name "${FILENAME}" then add the other bits one by one.
Jose Mosquera
Honored Contributor

Re: find hint

Hi pals,

I get it! An extra (unwished) double quotation marks character included into FILENAME variable was the pain!

In any case, thank you very much and points for everybody!

Rgds.
Jose Mosquera
Honored Contributor

Re: find hint

Thank you and best regards.