[ale] bash script

Charles Shapiro hooterpincher at gmail.com
Tue Sep 11 10:39:17 EDT 2007


Gee, seems kind of backwards.

How 'bout:

#!/bin/bash
DIRS="/var/www/zm/events/1 /var/www/zm/events/2 /var/www/zm/events/3" # Et
cetera

for kk in ${DIRS}
do
   /usr/bin/find $kk -name "*.log" -mtime 5 -exec rm -f {} \;
done

NB I ain't tested this. I' put an "echo" in front of the "find" command to
do that part.

And of course if your dirs are all numeric, you could calculate the names
assuming that you didn't need to be specific on which ones to chop:

#!/bin/bash
kk=1
LIMIT=16
while [ ${kk} -lt ${LIMIT} ]
do
    /usr/bin/find /var/www/zm/events/$kk -name "*.log" -mtime 5 -exec rm -f
{} \;
    let kk=$kk+1
done

Without knowing more specifics, it's hard to tell what the really correct
approach might be. Of course,  a production script would have significant
variables (e.g "LIMIT", above, and probably the directory name stem
("/var/www/zm/events") )  at least abstracted to the top and possibly set
with arguments, and would include documentation and logging as well. .

-- CHS


On 9/11/07, Marvin, International Martian of Mystery <
marvin.higginbottom at gmail.com> 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.
>
> This is what I've come up with:
>
>
>
>
>
>
>
> #! /bin/sh
>
> ## Remove ZoneMinder events cache
> ## There's gotta be a better way  to
> ## do this!
>
> EXECUTE="/usr/bin/find ./ ! -name "*.log" -mtime 5  -print | /sbin/rm
> -Rf $1"
>
>
> cd /var/www/zm/events/1
>         $EXECUTE
> cd /var/www/zm/events/2
>         $EXECUTE
> cd /var/www/zm/events/3
>         $EXECUTE
> cd /var/www/zm/events/5
>         $EXECUTE
> cd /var/www/zm/events/6
>         $EXECUTE
> cd /var/www/zm/events/9
>         $EXECUTE
> cd /var/www/zm/events/10
>         $EXECUTE
> cd /var/www/zm/events/11
>         $EXECUTE
> cd /var/www/zm/events/12
>         $EXECUTE
> cd /var/www/zm/events/13
>         $EXECUTE
> cd /var/www/zm/events/14
>         $EXECUTE
> cd /var/www/zm/events/15
>         $EXECUTE
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list