[ale] bash script

Marvin, International Martian of Mystery marvin.higginbottom at gmail.com
Tue Sep 11 14:24:21 EDT 2007


On Tue, 2007-09-11 at 12:27 -0400, Daniel Kahn Gillmor wrote:

First:  thanks to everybody who've responded to this question. It's been
very enlightening.  :-)

I like this answer the best- because it whittles the process down to one
command.  Gotta like that.   



> On Tue 2007-09-11 10:18:17 -0400, Marvin, International Martian of Mystery wrote:
> 
> > I'd like some feedback/critique for a script I'm running as a cron job
> > daily on a box I administrate.  It's supposed to delete all the files it
> > finds that are 5 days or older.  
> 
> you don't say what other directories there are under
> /var/www/zm/events.  For example, are you deliberately skipping
> events/{4,7,8} for some reason?
> 
> Also, modern versions of GNU find have a -delete action [0].
> 
> i'm not entirely sure this does what you want, but i think it might
> be:
> 
> find /var/www/zm/events/{1,2,3,5,6,9,1{0,1,2,3,4,5}} -mtime +5 -a -type f -a ! -name '*.log' -delete
> 
> (entirely untested, i'm afraid)
> 
> notes:
> 
>  * i used -mtime +5 instead of -mtime 5 to catch files modified > 5
>    days ago.

Sweet.



> 
>  * i'm explicitly representing the conjunction of expressions in the
>    find statement (with -a), because i'm not confident that
>    conjunction is the default case.
> 
>  * i moved the negated test (! -name '*.log') to the end to make sure
>    the negation doesn't apply to anything else.  Other folks more
>    confident in their knowledge of find's operator precedence might
>    not care.

>  * i've added a test only for normal files (-type f), since you say
>    you want to delete files.  this avoids deleting subdirs, etc.

What I'm trying to delete are subdirs full of files, I'm afraid.
Zoneminder (the program producing the data I'm deleting) stores all it's
"events" in numbered sub-directories under a numbered directory
corresponding to the video channel producing the "events".  I want to
take out everything under the specified video channel's directory that's
5 days old or older.

If I remove the "-type f" flag from the above, will it kill the
directories under the ones indicated by the braces?



>  * you can test this command by replacing -delete with -print, if you
>    like.

Noted.




>  * if you really want to do this for all subdirs, not just the ones
>    specified above with curly-brace expansion, it'd probably be
>    simpler and more robust to begin the above command with:
>    
>     find /var/www/zm/events/*
> 

The only problem with that is I want to keep the numbered directories
corresponding to the video channels- I just want to kill all the subdirs
5 days or older under /var/www/zm/events/1/, for example.  

The /var/www/zm/events dir also contains configuration files for the
various used video channels I want to keep.  

But I think that overall, a version of your script modified to delete
the sub-dirs I want to clean out will be the one I use.  :-)  Thanx...















> hth,
> 
>         --dkg
> 
> [0] https://www.debian-administration.org/users/Steve/weblog/176
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list