Calling a find/remove within a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling a find/remove within a script
# 1  
Old 05-15-2017
Calling a find/remove within a script

Greetings all,

I am calling a remove from within a script that is used for a cleanup process.. It is not working as expected. Here is what I am doing.

I have a config file that lists out a directory name, and the options to run

Within the config file

Code:
DIR1="find /directory/holding"
DIR1OPTIONS="-type f ! -name \"*.gz\" ! -name "*PDF*" ! -name \"*TIF*\" -size +1000k -mmin +120 -exec gzip {}+"

I have another script that I am scheduling via an external tool to run- Simple.

Code:
#!/bin/ksh
#Script Below#
#Add additional lines to config options.
. ./prune.config
 $DIR1 $DIR1OPTIONS

It is not working. I am getting the below error-

Code:
find: incomplete statement

I threw an echo statement under the script that runs and I am getting the output, it looks correct. If I copy it and then run it, it works.

I suspect something is up with the config file. Any suggestions
# 2  
Old 05-15-2017
try this:
Code:
DIR1OPTIONS='-type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {}+'

# 3  
Old 05-15-2017
Looks like the echo stays the same. I was trying to escape the items identified in -name.

Code:
[me@server:/me/scripts]> ./prune.ksh
find: incomplete statement
find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {}+

# 4  
Old 05-15-2017
Quote:
Originally Posted by jeffs42885
Looks like the echo stays the same. I was trying to escape the items identified in -name.

Code:
[me@server:/me/scripts]> ./prune.ksh
find: incomplete statement
find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {}+

Hi,
Try this:

Code:
find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {}+ \;

The final \; for the exec clause is mandatory. I don't know why you add the plus sign to the filename : {}+ .

Try
Code:
-exec gzip {} \;

.


Regards.
# 5  
Old 05-15-2017
Same result.

Code:
[me@server:/me/scripts]> ./prune.ksh
find: incomplete statement
find /directory/holding -type f ! -name *.gz ! -name *PDF* ! -name *TIF* -size +1000k -mmin +120 -exec gzip {} \;

# 6  
Old 05-15-2017
The following may help:

Code:
ksh -x ./prune.ksh

So we can see how is parsed the statement.

Regards.
# 7  
Old 05-15-2017
Code:
[me@server:/me/scripts]> ksh -x ./prune.ksh
+ . ./prune.config
+ + date +%OY%Om%Od
TIMESTAMP=20170515
+ DIR1=find /directory/holding
+ DIR1OPTIONS=-type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {} \;
+ find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {} \;
find: incomplete statement
+ echo find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {} \;
find /directory/holding -type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Calling specific characters from a find variable

I'm trying to do something like this: find . -name blablabla -exec ln -s ./"{:53:14} blablabla" \; The idea is find blablabla and create a symbolic link to it using part of it's path and then it's name, "blablabla." I just don't know if I can call characters out of a find variable. ... (16 Replies)
Discussion started by: scribling
16 Replies

3. Shell Programming and Scripting

find -exec How to add additional parameter when calling a funtion

Hello Current working script is : # # my_script BEGIN # function a_function { FIRST_PARAM="$1" DO_SOMETHING "$FIRST_PARAM" } export -f a_function START_HERE="/home/some_user/Documents" find $START_HERE" -exec bash -c 'a_function "$0" ' {} \; (5 Replies)
Discussion started by: jcdole
5 Replies

4. Shell Programming and Scripting

Can't remove spaces with sed when calling it from sh -c

The following command works echo "some text with spaces" | sh -c 'sed -e 's/t//g''But this doesn't and should echo "some text with spaces" | sh -c 'sed -e 's/ //g''Any ideas? (3 Replies)
Discussion started by: Tribe
3 Replies

5. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

6. Shell Programming and Scripting

Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Discussion started by: leepet01
5 Replies

7. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

8. Shell Programming and Scripting

Script to find and remove characters

Hi. I have many files in a folder, and even more in the subfolders. I need a script that finds and removes certain characters (them being /n in this one) in the files in the folder and it's subfolders. So, could someone write me a script that works in Linux, does this: Searchs for "/n" in... (5 Replies)
Discussion started by: Zerby
5 Replies

9. Cybersecurity

i am trying to find out who is calling me

they are having an operator call my home line and also my cell number and they are typing and the operator tells me what they are typing on their computer. i nevere heard of this. it is new to me. it is free the operator said, they knew my name and also a friend of mine's name...the phone says the... (2 Replies)
Discussion started by: gail
2 Replies

10. Programming

How to Find who is calling me?

Hi, I was trying to find from the function which is called by some other function but is it possiable by the calling funcation that who is calling me? For example int function1() { // do something return 0 ; } char function2() { // do something function1() ; // is... (9 Replies)
Discussion started by: uxbala
9 Replies
Login or Register to Ask a Question