Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Calling a find/remove within a script

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 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 to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find -exec How to add additional parameter when calling a funtion jcdole Shell Programming and Scripting 5 10-10-2017 08:50 AM
Can't remove spaces with sed when calling it from sh -c Tribe Shell Programming and Scripting 3 12-13-2014 03:31 AM
calling a shell script present on another server using perl script. anandgodse Shell Programming and Scripting 3 07-18-2012 01:24 AM
How we can pass the argument when calling shell script from perl script anuragpgtgerman Shell Programming and Scripting 5 03-21-2012 03:57 PM
Shell script calling Perl function, sort and find data, write to new files kowit010 Homework & Coursework Questions 6 11-02-2011 09:39 PM
Syntax error calling TCL script from shell script marcoss90 Shell Programming and Scripting 1 03-13-2011 09:14 AM
Running a unix script(which is calling another script inside that) in background rohithji Shell Programming and Scripting 2 11-06-2009 12:52 AM
Script to find and remove characters Zerby Shell Programming and Scripting 5 01-30-2008 01:16 AM
i am trying to find out who is calling me gail Security 2 07-09-2005 06:48 PM
How to Find who is calling me? uxbala Programming 9 02-15-2005 12:58 AM


All times are GMT -4. The time now is 03:50 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password