Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-15-2017
jeffs42885 jeffs42885 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 27 July 2017, 10:47 AM EDT
Location: PA
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 05-15-2017
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 23 September 2017, 8:59 PM EDT
Location: Foxborough, MA
Posts: 8,191
Thanks: 226
Thanked 782 Times in 730 Posts
try this:

Code:
DIR1OPTIONS='-type f ! -name "*.gz" ! -name "*PDF*" ! -name "*TIF*" -size +1000k -mmin +120 -exec gzip {}+'

Sponsored Links
    #3  
Old Unix and Linux 05-15-2017
jeffs42885 jeffs42885 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 27 July 2017, 10:47 AM EDT
Location: PA
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
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 Unix and Linux 05-15-2017
AbelLuis AbelLuis is offline
Registered User
 
Join Date: Jan 2014
Last Activity: 10 August 2017, 11:24 PM EDT
Posts: 28
Thanks: 9
Thanked 10 Times in 10 Posts
Quote:
Originally Posted by jeffs42885 View Post
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.
Sponsored Links
    #5  
Old Unix and Linux 05-15-2017
jeffs42885 jeffs42885 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 27 July 2017, 10:47 AM EDT
Location: PA
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts
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 {} \;

Sponsored Links
    #6  
Old Unix and Linux 05-15-2017
AbelLuis AbelLuis is offline
Registered User
 
Join Date: Jan 2014
Last Activity: 10 August 2017, 11:24 PM EDT
Posts: 28
Thanks: 9
Thanked 10 Times in 10 Posts
The following may help:


Code:
ksh -x ./prune.ksh

So we can see how is parsed the statement.

Regards.
Sponsored Links
    #7  
Old Unix and Linux 05-15-2017
jeffs42885 jeffs42885 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 27 July 2017, 10:47 AM EDT
Location: PA
Posts: 95
Thanks: 14
Thanked 0 Times in 0 Posts

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 {} \;

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can't remove spaces with sed when calling it from sh -c Tribe Shell Programming and Scripting 3 12-13-2014 03:31 AM
Shell script calling Perl function, sort and find data, write to new files kowit010 Homework & Coursework Questions 6 11-02-2011 09:39 PM
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 09:36 PM.