in reply to Re: Automatically delete files
in thread Automatically delete files

Thankyou,

I think i will use the cron option, just in case as Data64 pointed out and sparkyichi was good enough to convey that i may have a problem if i use the sleep option and the server reboots.

I have looked at cron through google and found some info about the * in the time and day etc but could you just explain the "30 1" and "-exec /bin/rm '{}' \;" parts.

I get that -exec is trying to execute somthing but what, does this remove the dir, and if so can i put my perl script call in here instead so it reads:

30 1 * * * -mtime 1 -exec/home/march05/msc0516/public_html/Blast/dele +teFiles.pl;

Replies are listed 'Best First'.
Re^3: Automatically delete files
by davidrw (Prior) on Aug 02, 2005 at 16:30 UTC
    The basic format of the crontab entry is
    minute hour day_of_month month day_of_week your_command_to_execute
    The '*' for the first five fields just means 'every'. So to run a command every day at 1:30 we use:
    30 1 * * * some_command
    See man 5 crontab for a fuller description of the values you can use in those first five columns.

    So now, the main part is what to put for "some_command".. i used this line, which is all part of a single find command:
    find /home/march05/msc0516/public_html/Blast/updated/ -mtime 1 -exec / +bin/rm '{}' \;
    This (man find) tells find to A) look in your Blast/updated/ directory, B) take files modified a day ago, and C) execute "/bin/rm FILENAME" for each one.

    If you wanted to simply cron your perl script instead, it would be something like:
    30 1 * * * /home/march05/msc0516/public_html/Blast/deleteFiles.pl
    Note also that the cron daemon will email you any output generated by the commands that are invoked by the crontab ... this is very handy for getting emails of errors.

    note that google(cron tutorial) will yield a slew of results.