Jump to content

Moving 1-day-old files to a 7-day archive with cron


HaLo2FrEeEk

Recommended Posts

I tried to make the title descriptive enough.  Basically, I have a php script set up to transfer a file from another server every 10 minutes (the file changes), and save it with a timestamp.  I havea  cron set up to delete the images after 1 day, but I'd like to archive them for a week then delete them.  Is there a way to do this?  I've tried a few cron commands like:

 

/usr/bin/find /home/halo2freeek/infectionist.com/misc/bungie_webcam/images -mtime +0 -exec rm {} \;

 

Which returned something about not being able to find the directory ../archive.  I thought, "ok, it doesn't like the relative path", so I tried:

 

/usr/bin/find /home/halo2freeek/infectionist.com/misc/bungie_webcam/images -mtime +0 -exec mv /home/halo2freeek/infectionist.com/misc/bungie_webcam/archive {} \;

 

Which returned:

 

mv: cannot overwrite non-directory `/home/halo2freeek/infectionist.com/misc/bungie_webcam/images/1218760203.jpg' with directory `/home/halo2freeek/infectionist.com/misc/bungie_webcam/archive/'

 

Now, I'm no expert, but I'm pretty sure I just told it to move the file that it found to the archive folder, not overwrite anything.

 

Is there any way to make this work?  I DO have a reason that I want the 7 day archive to be in a different folder.  The files I'm transferring are images, and I'm animating a day's worth of the images (those in the images folder) in a dynamically generated animated gif, I don't want to animate 7 days though, but I want them to be viewable by people.

 

Can someone help me out?

Link to comment
Share on other sites

That didn't work, it's still giving me the overwrite error.  It's saying I can't overwrite non-directory (filename) with the archive folder, like I'm trying to move the folder to the picture, and not the other way around...

 

And in addition to this, I have a folder called gifs inside the regular images folder.  When I run the command to look in the images folder, it searches subfolders, and will thus move the gif to the root archive folder, I want it moved to archive/gifs.  To do this, would I simply run the command first looking in the gifs folder, then looking in the images folder, that way the gifs get moved first?

Link to comment
Share on other sites

Oh, and to answer this....

 

To do this, would I simply run the command first looking in the gifs folder, then looking in the images folder, that way the gifs get moved first?

 

Yes, that would probably be the simplest solution.

Link to comment
Share on other sites

Ok, turns out that though this DID work, it seems to want to move some of the gifs to the main images folder, instead of the gifs folder.  Now, I could seperate the two, have gifs and images bee in one folder, and not gifs being a subdirectory of images, but is there a way to tell find to NOT look in subdirectories?  That would simplify things a bit.  I don't know why it happened, but when I looked today, there were 2 gifs in the wrong folder.  I can't have that happen consistently, so, is there a way to make it not look in the subdirectories of the folder it's searching?

Link to comment
Share on other sites

is there a way to tell find to NOT look in subdirectories?

 

Yeah, the -maxdepth option.

 

/usr/bin/find /home/halo2freeek/infectionist.com/misc/bungie_webcam/images -maxdepth 1 -mtime +0 -exec mv {} /home/halo2freeek/infectionist.com/misc/bungie_webcam/archive/ \;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.