Login or Register to Ask a Question and Join Our Community


Extrange Find command Issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extrange Find command Issue
# 1  
Old 08-07-2009
Extrange Find command Issue

Hi all, i'm new at shell scripting world...
I'm working on a script for searching old files on a server, this scripts runs with a configuration file wich indicates where to search the files, the script should search for all files that are older than an x qty of days, and the only clue that i have is the main folder, that part is done. Now, i should stop the recursive search through the subfolders (wich i don't know what their names are) if an option of the configuration file is choosen, i've found a way to do this and it works perfecly out of my shell script (i just execute the line and it works) but it doesn´t work when i execute it through the shell file i get an error wich says "missing conjunction", i've tryed quoting the name of the path, the name but i can't make it work, here is the script:

Code:
_LoadConfiguration() {
   if [ -f $CLEANSVRCONFIGFILE ] ; then
      WORKDIR=`cat $CLEANSVRCONFIGFILE | grep workdir | cut -f2 -d=`
      DAYSOLD=`cat $CLEANSVRCONFIGFILE | grep daysold | cut -f2 -d=`
      FINDSUBFOLDERS=`cat $CLEANSVRCONFIGFILE | grep findsubfolders | cut -f2 -d=`
      FINDPATTERN=`cat $CLEANSVRCONFIGFILE | grep findpattern | cut -f2 -d=`
      SEARCHPATTERN=`cat $CLEANSVRCONFIGFILE | grep searchpattern | cut -f2 -d=`
      OUTPUTFILE=`cat clean.cleanconfig | grep outputfile | cut -f2 -d= | cut -f1 -d\<` 
      OUTPUTFILE=$OUTPUTFILE""`date +"%Y%m%d%H%M%S.txt"`
      FILESIZE=`cat $CLEANSVRCONFIGFILE | grep filesize | cut -f2 -d=`
      BASEDIR=`cat $CLEANSVRCONFIGFILE | grep workdir | cut -f2 -d= | xargs basename`
   else
      echo
      echo "Configuration file not found ($CLEANSVRCONFIGFILE)."
      echo
      exit 1
   fi
}
_RunGenerateList() {
if [ ! "$WORKDIR" == "" ] ; then
    filter_list=$filter_list"\"$WORKDIR\""
fi
if [ "$FINDSUBFOLDERS" == "" ] ; then
    filter_list=$filter_list" \\( ! -name \"$BASEDIR\" -prune \\)"
fi
if [ ! "$SIZE" == "" ] ; then
    filter_list=$filter_list" -size "$FILESIZE
fi
if [ ! "$DAYSOLD" == "" ] ; then
    filter_list=$filter_list" -mtime -"$DAYSOLD
fi
if [ ! "$FINDPATTERN" == "" ] && [ ! "$SEARCHPATTERN" == "" ] ; then
    filter_list=$filter_list" -name *"$SEARCHPATTERN"*"
fi
if [ ! "$filter_list" == "" ] ; then
    filter_list=$filter_list" -type f  "
    find $filter_list -ls
fi
}
if [ $# -gt 0 ] ; then
    if [ $1 == "-cfg" ] ; then #the user want to generate the list of files
        CLEANSVRCONFIGFILE=$2
        _LoadConfiguration
        _RunGenerateList
    fi
fi

please i anyone can help me i'm just stuck with this Smilie

Last edited by Yogesh Sawant; 08-10-2009 at 03:03 AM.. Reason: added code tags
# 2  
Old 08-07-2009
can you post the contents of $filter_list right before the find? perhaps with an echo $filter_list
# 3  
Old 08-07-2009
Hi, the result is
Code:
/mydir/mysubdir \( ! -name mysubdir -prune \) -type f -mtime -3

so, the find looks like this
Code:
find /mydir/mysubdir \( ! -name mysubdir -prune \) -type f -mtime -3 -ls

it works if i copy the echo result (the line over this one) and execute it on my AIX console, but it doesn't work when i execute it from my shell script.

i've tryed this way too
Code:
find /mydir/mysubdir \( ! -name "mysubdir" -prune \) -type f -mtime -3 -ls

and the result is the same

"missing conjunction"

Thanks in advance

Last edited by Yogesh Sawant; 08-10-2009 at 02:58 AM.. Reason: added code tags
# 4  
Old 08-09-2009
Maybe you mean "-print" rather than "-ls":

Code:
find /mydir/mysubdir \( ! -name "mysubdir" -prune \) -type f -mtime -3 -print

# 5  
Old 08-10-2009
No, -ls is a valid option... i'm using it instead of find...| xargs ls
# 6  
Old 08-10-2009
Though I can't reproduce your syntax error, I get no output unless I type the parameters in this order:

Code:
find /mydir/mysubdir -type f -mtime -3 \( ! -name "mysubdir" -prune \) -print

# 7  
Old 08-10-2009
i'm getting the same error both ways
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Issue in Find and mv command

Hi I am using the below code to find mv the files. Files are moving to the Target location as expected but find is displaying some errors like below. find ./ -name "Archive*" -mtime +300 -exec mv {} /mnt/X/ARC/ \; find: `./Archive_09-30-12': No such file or directory find:... (6 Replies)
Discussion started by: rakeshkumar
6 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

Performance issue while using find command

Hi, I have created a shell script for Server Log Automation Process. I have used find xargs grep command to search the string. for Example, find -name | xargs grep "816995225" > test.txt . Here my problem is, We have lot of records and we want to grep the string... (4 Replies)
Discussion started by: nanthagopal
4 Replies

5. 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

6. Shell Programming and Scripting

Issue with Find Command

Hi All, I'm a bit new to Linux environment, moderately okay when it comes to Unix AIX. I'm facing an issue while trying to run a simple find command: $ for file in `find . -name *.*` > do > ls $file > done This is throwing the following error: Strangely, a few minutes... (4 Replies)
Discussion started by: adi_2_chaos
4 Replies

7. 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

8. Shell Programming and Scripting

Issue with Find command on Linux

Hi, I am issuing find command below mentioned ways but it givs different count. I don't understand the behaviour. Could any one have any clue? $ find . -mtime -5 -maxdepth 1 -exec ls -lrt {} \; | wc -l 169 $ find . -mtime -5 -maxdepth 1 | wc -l 47 $ find . -mtime -5 -maxdepth 1 | wc -l... (2 Replies)
Discussion started by: siba.s.nayak
2 Replies

9. UNIX for Dummies Questions & Answers

Issue with find command using links

Hi, Having a simple issue with find command on Sun. The command works fine if the variable is set to the actual filesystem but fails when the variable is set to a link which is pointing to the same filesystem. export DUMPDEST=/oradata1/exports/pbm - Set the variable ... (2 Replies)
Discussion started by: win_vin
2 Replies

10. Shell Programming and Scripting

An issue with find command.

Hi all, I have a shell script(ksh) which has the code as follows. ------------------ cd $mydir for i in `find ./ -type f -mtime +$k` do echo $i done ----------------------- And in $mydir , i have some files which have space in theie names like "Case att15". The out put of the... (6 Replies)
Discussion started by: rajugp1
6 Replies
Login or Register to Ask a Question

Featured Tech Videos