Removing old files that contain a phrase using crontab

Removing old files that contain a phrase using crontab

Post by Bill » Thu, 08 Sep 2005 23:01:48



What do I have to add to the job below, to remove old files that begin
with decrypt_DH9383PS.log and contain the phrase "No Matches" in the
file contents?

00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
-exec rm {} \;

Thanks in advance.

 
 
 

Removing old files that contain a phrase using crontab

Post by Icarus Sparr » Fri, 09 Sep 2005 02:00:14



Quote:> What do I have to add to the job below, to remove old files that begin
> with decrypt_DH9383PS.log and contain the phrase "No Matches" in the
> file contents?

> 00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
> -exec rm {} \;

> Thanks in advance.

00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
        -exec sh -c 'grep "No Matches" $1 >/dev/null 2>&1 && rm $1' {} {}  \;

This is a tiny shell script (written inline), which runs grep and if
that reports success then runs rm. The doubled {} are to handle case
that $0 is assigned the first arguement, and $1 the second one.

 
 
 

Removing old files that contain a phrase using crontab

Post by Chris F.A. Johnso » Fri, 09 Sep 2005 02:20:58



> What do I have to add to the job below, to remove old files that begin
> with decrypt_DH9383PS.log and contain the phrase "No Matches" in the
> file contents?

> 00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
> -exec rm {} \;

    Write a script to do it, and call the script from find.

## This is one long line:
00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" \
                             -mtime +14 -exec script {} \;

--
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>

 
 
 

Removing old files that contain a phrase using crontab

Post by cyril_vievi.. » Sat, 10 Sep 2005 19:21:23



> What do I have to add to the job below, to remove old files that begin
> with decrypt_DH9383PS.log and contain the phrase "No Matches" in the
> file contents?

> 00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
> -exec rm {} \;

> Thanks in advance.

The easiest solution :

find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14 | xargs
grep No Matches | cut -d":" -f1 | sort -u | xargs rm

 
 
 

Removing old files that contain a phrase using crontab

Post by Enrique Perez-Terro » Sat, 10 Sep 2005 21:34:12




>> What do I have to add to the job below, to remove old files that begin
>> with decrypt_DH9383PS.log and contain the phrase "No Matches" in the
>> file contents?

>> 00 4 * * * find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14
>> -exec rm {} \;

>> Thanks in advance.

> The easiest solution :

> find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14 | xargs
> grep No Matches | cut -d":" -f1 | sort -u | xargs rm

Oops, you need quotes around No Matches.

Just for fun, a further refinement: grep -l will output file names only,
and each file at most once, obviating the need to cut and sort -u.

   find /sap_basis/log -name "decrypt_DH9383PS.log*" -mtime +14 |
   xargs grep -l "No Matches" | xargs rm

Regards,
Enrique

 
 
 

1. HOW using 1 files contents as info to delete the second files containing that pattern?

Given 2 files

one file having a list of names
the other containing a list of names to delete from the first

use sed or diff or write a script?

problem is I don't know about file i/o in scripts yet I guess.

ie  using read command on a file reading the first line in the file,
then using next after the 2 lines are compaired and equal == must be
deleted.
read next line as the pattern, search untill found (records match
exactly) then delete, read next line in file as the pattern to search
until found.......again untill are are deleted.

How -I just have bits and pieces now..

Help and thank you for all you do ! really !
matt

2. exit_mmap and down_interruptible

3. link a crontab -> "crontab -e" remove link

4. HELP: fork/exec and std* fd's

5. Question about "Cannot open or remove a file containing a running program"

6. mountd and domain

7. How to remove many files which contains dash in filename?

8. WHEE!!!! Linux on an 386 (for real) w/ 4M

9. Cannot open or remove a file containing a running program...

10. FTP Problem of AIX (annot open or remove a file containing a running program)

11. file removing crontab

12. df shows 100% used, after I removed files, it's still 100% used

13. Removing funny files (Re: how do i remove a file with a ~ in it ????)