Variable for -name causing issue in Find command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Variable for -name causing issue in Find command
# 1  
Old 03-24-2006
Variable for -name causing issue in Find command

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:

Code:
#! /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:

Code:
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:

Code:
FilesToFind="\"*.dat\""
ListOfFiles=`find . -mtime +30 -type f -name ${FilesToFind}`

Code:
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...
# 2  
Old 03-24-2006
Code:
#! /usr/bin/sh -f

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

# 3  
Old 03-24-2006
Thanks reborg!

Changing it to, FilesToFind='*.dat', solved the issue.

Les...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris 5.8 Upgrade is causing Date format issue.

Hi I have a JAVA based application in development and production environment. These two environments are exactly identical in terms of OS, hardware and application components. Initially the OS was Solaris 5.6 and the application was working fine in both environments. But later when the OS... (12 Replies)
Discussion started by: Jayant Tripathi
12 Replies

2. Shell Programming and Scripting

Find command issue

Hi Guys, I have a file called error.logs. am just trying to display the content in the file which was modified last 1 day. I tried below command but it doesnt give the proper output. find /u/text/vinoth/bin "error.logs" -mtime -1 -exec cat {} \; >> mail.txt Any help is much... (21 Replies)
Discussion started by: Vinoth Kumar G
21 Replies

3. Shell Programming and Scripting

Find command issue

Guys, Here is my requirement.. Sample.cfg file="*log.gz *txt.gz" sample.sh #!/bin/sh . $HOME/Sample.cfg find . -name "$file" -mtime +20 -exec ls -la {} \; Its not finding the given *log.gz and txt.gz files. Could anyone please help me? (8 Replies)
Discussion started by: AraR87
8 Replies

4. Shell Programming and Scripting

Text qualifier issue causing data alignment problem

Hello Everyone, I have a csv file with text qualifier as "" and data similar to below: "1","abc","address1","US" "2","def","address1 "characters in double-quote" address2","IND" "3","ghi","address1","UK" In above example, for record 2, we have an issue as in column3 contains double... (2 Replies)
Discussion started by: AnkitSenghani
2 Replies

5. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

6. Shell Programming and Scripting

Issue in using variable within sed command

Hi All, I am trying to use a variable within the sed command but I am not able to get the output. When I am using the following command (without variable) its working fine: sed -n '/2011\/12\/10 18:11:11./,$p' < Log.txt > Delta_Log.txt But when I am putting the value 2011\/12\/10... (4 Replies)
Discussion started by: acoomer
4 Replies

7. Shell Programming and Scripting

Awk script problem - Variables Causing Issue

can someone please explain to me what i'm doing wrong with this code: WELT=$(awk '(($1 ~ "^${caag}$") || ($2 ~ "^${caag}$"))' /tmp/Compare.TEXT) when run from the command line, it works. but it seems to be having a problem doing the comparison when variables are involved. i tested from... (1 Reply)
Discussion started by: SkySmart
1 Replies

8. Linux

find command issue

Hi, I am not root user. I am trying to find the file which has contains pattern "fvsfile" in root directory. If i run the find cmd then i got permission denied and all the files are listed include pattern files. i cant get file name yet find . print | xargs grep -i "fvsfile" I want... (2 Replies)
Discussion started by: Mani_apr08
2 Replies

9. UNIX for Dummies Questions & Answers

Find command issue

I am currently using below command to get the 1st three characters of a file(PDM). Issue is, when i use find command in root dir, it finds all the files in sub dir also. How to limit the find command search to a given path only(ie: say only find file in apps/cmplus/datamigration/data path... (3 Replies)
Discussion started by: abhi_n123
3 Replies

10. IP Networking

Could a tcp issue be causing a null pointer exception?

The client's app gets a 'suspend error' which they say is due to a null pointer exception. Application people say nothing's wrong with the app. Network people say the network's fine. I'm supposed to see what's wrong with the system to be causing this error. I checked the NIC card settings, which... (1 Reply)
Discussion started by: pmichner
1 Replies
Login or Register to Ask a Question