[Tfug] Cron job in Ubuntu - something is wrong :( - halp?

Nate nate at torzo.com
Mon Feb 9 12:28:21 MST 2009


Everyone else has all valid points, but in the interest of why this
isn't working... this should fix it all up, and this is how I would
rewrite the cron:

01 04 * * * find /media/disk -mtime +90 -exec rm {} \; && echo "Purge of
camera files older than 90 days successful: $(date)" >>
/home/camera/Desktop/purge.log

This gets rid of the superfluous * on the path (find does that
functionality already, and the * could end up causing you errors if
there are too many arguments), fixing the second double-quote, and
putting it all in one line.  If the find fails, then the "successful"
message doesn't print.  It's not likely that the find is going to fail,
though, but it could if the directory doesn't exist, such as if the
drive isn't mounted.

However I would probably write it more like this:

01 04 * * * echo -n "Num files deleted: " >>
/home/camera/Desktop/purge.log; find /media/disk -mtime +90 -exec rm -v
{} \; | wc -l >> /home/camera/Desktop/purge.log && echo "Purge of camera
files older than 90 days successful: $(date)" >>
/home/camera/Desktop/purge.log

This will output every day:

Num files deleted: 9999
Purge of camera files older than 90 days successful: <date>

in the file every day.

Or you could remove the pipe to wc and get the list of files that were
actually deleted.

Obviously this is ugly, so I would recommend putting this into a shell
script instead of all on one line.  It would make error reporting more
robust, for one.

All useless since you found a better solution, but hey, I think it's fun
to do stuff like this =)

Nate

Jim March wrote:
> OK, so I have a friend's system set up purely as a video camera
> monitor running Zonealarm with six cameras.  Works great - it's
> running Ubuntu Hardy.
> 
> Since Zonealarm takes a bazillion little still images and the number
> of picture files can get crazy, images are saved on a dedicated 500gig
> drive formatted with ReiserFS.
> 
> Great.  But I can't have the disk fill up, so I have a cron job set to
> do a purge of files older than 90 days.  It's not working.
> 
> Sigh.
> 
> Here's the contents of the root crontab entries...the username on this
> system is "camera":
> 
> ---
> PATH=/usr/sbin:/usr/bin:/sbin:/bin
> 01 04 * * * find /media/disk/* -mtime +90 -exec rm {} \;
> 01 04 * * * echo "Purge of camera files older than 90 days
> successful:" $(date)" >> /home/camera/Desktop/purge.log
> ---
> 
> The command:
> 
> sudo  find /media/disk/* -mtime +90 -exec rm {} \;
> 
> ...works just fine.  No purge.log file is being created.  I put this
> in the root crontab via:
> 
> sudo crontab -e
> 
> So...what the heck?
> 
> [wimper]
> 
> Jim
> 
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org




More information about the tfug mailing list