The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Spliting file based on condition Raamc Shell Programming and Scripting 2 05-15-2008 11:51 AM
How to split the String based on condition? sankar reddy Shell Programming and Scripting 2 03-19-2008 07:48 AM
command for deleting log files based on some condition pulkit Shell Programming and Scripting 4 01-09-2008 06:17 AM
Read file based on condition sbasetty Shell Programming and Scripting 5 02-01-2007 02:54 AM
Splitting a file based on some condition and naming them srivsn Shell Programming and Scripting 1 12-07-2005 11:27 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-25-2009
Katkota Katkota is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 115
Red face How to search then remove based on condition

Folks;
I'm trying to write a script to scan through a directory tree then for each file it finds, it run a command line tool, then if the results include the word "DONE", it removes the file.
In more details;
i have a Linux directory tree such as "/opt/grid/1022/store"
I'm trying to write a script going through this tree and every file it finds, it should run this command on it:

/opt/dev/chktool -getstat file_name |grep -v "DONE"

If the output include the word "DONE" then we need to remove it, if not, skip to the next one.

Any help is greatly appreciated
  #2 (permalink)  
Old 06-26-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
You may never get "DONE" because you are using grep -v.
If I understood your query properly, you probably need this...
Code:
for file_name in `find . -name 'pattern' -print`
do
   if [[ `/opt/dev/chktool -getstat $file_name |grep -c "DONE"` -gt 0 ]]; then
      #rm $file_name
   fi
done
  #3 (permalink)  
Old 06-26-2009
Katkota Katkota is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 115
But i don't know the file names, I need to run the tool on any file that can be in the directory tree
  #4 (permalink)  
Old 06-26-2009
arunsoman80 arunsoman80 is offline
Registered User
  
 

Join Date: Jul 2008
Location: New York
Posts: 45
Try this:

Code:
for file_name in `ls /opt/grid/1022/store`
do
    if [[ ! -z `/opt/dev/chktool -getstat $file_name |grep "DONE"` ]]; then   
          rm -f ${file_name}
    fi
done
regards,
Arun.
  #5 (permalink)  
Old 06-26-2009
Katkota Katkota is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 115
I still see "file_name" in the if statement.
I think i didn't explain it better,
What i'm looking for is to go through the directory tree, find any file under any subdirectory then run the tool on it, if the output include the word "DONE" then remove the file, if not, leave the file alone and go to the next file and do the same thing.

I hope that makes it more clear
  #6 (permalink)  
Old 06-26-2009
arunsoman80 arunsoman80 is offline
Registered User
  
 

Join Date: Jul 2008
Location: New York
Posts: 45
Did you even try the code that rakesh and I posted here?

regards,
Arun.
  #7 (permalink)  
Old 07-01-2009
Katkota Katkota is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 115
I did try it but i'm getting "failed to open the next directory"

How can i make it go search every directory and subdirectory for files then perform the tool on every file it find?
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0