|
OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
Delete Files By Schedule
Hi,
I am currently in the process of setting up a temporary file storage server. I am trying to have a 'script' running which will automatically remove files older than X number of days. File upload/retrieval is done via FTP. So the script will need to be run separately of this. Basically the file system will look something like this: [FTP ROOT] -> [username] -> uploaded files and directories Ideally I would like to a) remove all files older than X days and than after Y remove all files and directories including the [username]. I think I know how to do this (more or less) however I would like to know from others what might be the best way of doing this. Simplicity is ideal. I would also prefer not to have to install additional software unless its really worth it. Your help is appreciated. Thanks |
|
||||
How I would first try to do it:
a cron job A that uses find to recurse for all files/dir's in the target hier and rm -rf's them if criteria X are met. a cron job B that uses find to do likewise but for Y instead of X. GNU Find#time Another trick would be using a cronjob to run a custom made hunt & kill script or a self-rolled daemon to hunt and peck the files, perls a nice handler for that. But cron+find should be able to do it all.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
|||
Hi Terry thanks for the reply.
Would you happen to have an example command line for cron? Say for something that will check every 5 minutes and will remove all files older (but not younger) than 7 days. Thanks for your help! Last edited by plexter; 31st May 2008 at 10:48 PM. |
|
||||
Something like
cd /var/ftp (or wherever you keep the files) /usr/bin/find ./ -type f -mtime +7 -exec rm -f '{}' + -type f file -mtime + 7 older than 7 days -exec rm -f '{}' + That + at the end was something I found while googling--I'm trying to remember its purpose. Ah, I think it was a way to avoid getting the error of filelist too long. http://www.hccfl.edu/pollock/Unix/FindCmd.htm WARNING: DANGER and all that stuff. I would definitely test it with echo rm rather than just rm before putting it into action. |
|
||||
Not familiar with all of finds many innerds so I didn't know that, thanks a lot for the info about the + Scottro.
And yeah, testing with echo is one of the scripters best friends.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
|||
Hello all,
Thank you very much for your replies. scottro: I am having trouble getting your command to work. I tried inputting into CRON 30 * * * * cd /usr/path && /usr/bin/find ./-type f -mtime +7 -exec rm -f '{}'+ and 30 * * * * cd /usr/path /usr/bin/find ./-type f -mtime +7 -exec rm -f '{}'+ and nothing seems to happen. I have also tried simply typing the command on the command line and I get dropped into a > prompt where I do not seem to be able to do anything. Or it says "find: -exec: no terminating ";" " I tried adding a ; but that didnt seem to help. I am not sure if I am doing something wrong, if cron is not running for root??? or what could be up. Oh and I setup cron by: crontab -u root -e Help would be greatly appreciated. |
|
|||
$ /usr/bin/find /usr/path -type f -mtime +7 -exec ls {} \; That would list files older then 7 days, adjust it to your needs... |
|
|||
hmm.. thanks BSDfan666
I issued the command: /usr/bin/find /path/ -type f -mtime +7 -exec rm -f {} \; and it removed the files older than 7. However it does not seem to run when I put it as a crontab. I suspect the cron job is not even running. Do I have to 'enable' cron? Any ideas? Thanks for your help. |
|
|||
I just don't get it... I'm positive CRON is not running the command now.
I have done the following: mkdir /path/LOGS crontab -e Code:
5 * * * * /usr/bin/find /path/ftp/ -print -type f -mtime +7 -exec rm -f {} \; > /path/LOGS/deleted.log I do not see anything show up in the log (file does not even get created) and my files older than 7 days are still there. Does anyone here have more experience with CRON who might know why it is not running? Thanks a lot. |
|
||||
You have what appears to be shell script, rather than a single executable command in your crontab entry.
Stick your shell script in a text file. Make your first line of that file: #!/bin/shAfter saving the file, use chmod +x to mark the file executable. Edit your crontab entry to make that file the command. |
|
|||
Hi again,
I just wanted to let you know that with your help all seems to be working now. I've tested and the script seems to run as planned. Thanks a lot for your help! |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
FreeBSD console delete key | graudeejs | FreeBSD General | 4 | 24th August 2008 01:37 PM |
Cannot delete it.... | graudeejs | FreeBSD General | 9 | 20th July 2008 12:45 PM |
Delete Files By Schedule Continued | plexter | OpenBSD General | 4 | 28th June 2008 03:43 AM |
How to delete account? | khdf | Feedback and Suggestions | 5 | 9th May 2008 09:05 PM |