find command in shell script doesn't work


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find command in shell script doesn't work
# 1  
Old 09-22-2011
find command in shell script doesn't work

Hello all,

Something strange going on with a shell script I'm writing. It's trying to write a list of files that it finds in a given directory to another file. But I also have a skip list so matching files that are in that skip list should be, well uhm, skipped Smilie

Here's the code of my function:
Code:
 build_file_list ()
  {
  FOLDER=${1}
  if [ -d ${FOLDER} ]
  then
    ##build find statement
    SEARCH_STMT="find ${FOLDER} -type f ! -name \".*\" -mtime -${RETENTION} | egrep -vf ${SKIP_FILE}"
    ##SEARCH_STMT="find ${FOLDER} -type f ! -name \".*\" -mtime -${RETENTION}"
    ##find out if folder is serial or mfx
    #echo ${FOLDER}
    echo ${FOLDER} | grep /mfs/ >/dev/null
    if [ $? -eq 0 ] 
    then
      ##folder is mfs, write to temp_mfs file              
                  echo ${SEARCH_STMT} >> ${TEMP_MFS}
    else
      ##folder is serial, write to temp_serial file
                  echo ${SEARCH_STMT} 
                  ${SEARCH_STMT} >> ${TEMP_SERIAL}
    fi
  fi
  }

I've added an echo ${SEARCHT_STMT} for debugging reasons.

It shows me following output
Code:
 find /usr/app/etl/01/OTH/log/tra -type f ! -name ".*" -mtime -10 | egrep -vf /usr/app/etl/01/CLE/par/files_to_skip.par

When I execute this on the command line it works just fine. I get a nice list of files in that directory that have modified within the last 10 days.

However when I call this function in my script I get following error:

Code:
 find /usr/app/etl/01/OTH/log/log -type f ! -name ".*" -mtime -10 | egrep -vf /usr/app/etl/01/CLE/par/files_to_skip.par
  find: bad option |
  find: [-H | -L] path-list predicate-list

Can anyone help me here? How's it possible that when I just run the line it works but from my script it doesn't?

Any help welcome
# 2  
Old 09-22-2011
Code:
 
bash-3.00$ a="ls | grep txt"
 
bash-3.00$ echo $a
ls | grep txt
 
bash-3.00$ ${a}
|: No such file or directory
grep: No such file or directory
txt: No such file or directory
 
bash-3.00$ a="ls | grep txt"
 
bash-3.00$ eval $a
new.txt
old.txt

use eval
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 09-22-2011
Thanks, works perfectly Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Su to another user from root doesn't work within shell script

Hello I have a shell script that is run as root. Script rins ok until the point where it have to switch to user "mqm" to run other commands. It just hangs at the point of this line in the script su - mqm -c "dspmq" I ran the same commands at the terminal and they run fine. Any thoughts. (6 Replies)
Discussion started by: mo12
6 Replies

2. HP-UX

Find command doesn't return in shell script.

Hi All, I am using below snippet to search for a string (read from a file 'searchstring.out') in all locations (/) and then iterate over the files found to write the locations and the respective owner to an output file. However, this doesn't work as I believe the find command doesn't exit's... (11 Replies)
Discussion started by: Vipin Batra
11 Replies

3. Shell Programming and Scripting

Ssh remote command doesn't work from script file

I have 10 application servers in a distributed architecture generating their own application logs. Each server has application utility to continuously tail the log. for example following command follows tails and follows new logfiles as they are generated server1$ logutility logtype When I run... (8 Replies)
Discussion started by: indianya
8 Replies

4. Shell Programming and Scripting

Switching user inside a shell script doesn't seem to work

Linux version : Oracle Linux 6.4 Shell : Bash The following script will be run as root. During the execution, it should switch to oracle user and execute few commands. After googling and searching within unix.com , I came up with the following syntax ## Enclosing all commands in double... (7 Replies)
Discussion started by: John K
7 Replies

5. Shell Programming and Scripting

Why regex pattern doesn't work in find?

$ find /opt/data_* -maxdepth 3 -type d -name "main*" 2> /dev/null /opt/data_025/maindblogs /opt/data_026/maindblogs /opt/data_027/maindblogs /opt/data_028/maindblogs $ find /opt/data_* -maxdepth 3 -type d -name "rvlogs*" 2> /dev/null /opt/data_002/prod/rvlogs2_archive... (4 Replies)
Discussion started by: urello
4 Replies

6. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

7. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

8. UNIX for Dummies Questions & Answers

How to find size of each subdirect? du -sk | ls doesn't work

Using solaris 2.5.1, and how can I get a summary of the size of each subdirectory, say for /export/home, all the users? usually I do a du -sk dirname but I have to manually type in each name, is there a better way? Thanks, (3 Replies)
Discussion started by: kymberm
3 Replies

9. Shell Programming and Scripting

command line work script doesn't

Hello, I'm stuck and confused as to why when I execute things form the command line it works but when in a script it doesn't. My script: ### creating a lock on the console touch /var/run/console.lock chmod 600 /var/run/console.lock echo "$User" >>... (2 Replies)
Discussion started by: larry
2 Replies

10. Shell Programming and Scripting

grep doesn't work within shell script?

I am trying to run the following code from a script file but it complains that syntax of (both instances of) grep is wrong. When I copy and paste it to the terminal, it is OK. Any idea what the problem might be? set i = `grep -c #define flags.h` while ($i>20) @ i-- my func (`cat... (4 Replies)
Discussion started by: barisgultekin
4 Replies
Login or Register to Ask a Question