Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi guys, I'm trying to run a script on a folder to remove all the files every sunday at 23.00.
I've done a little bt of research, to find out what's involved etc, and what I got out of it is that I need to use cron to automate the process.
Needless to say I've never used it before o I had a look at a few examples and I came up with something, but I have no idea whether it is correct, so I was wondering if anyone could give it a quick glance.
Thi is the line of that will go in cron:
@reboot : Run once after reboot.
@yearly : Run once a year, ie. "0 0 1 1 *".
@annually : Run once a year, ie. "0 0 1 1 *".
@monthly : Run once a month, ie. "0 0 1 * *".
@weekly : Run once a week, ie. "0 0 * * 0".
@daily : Run once a day, ie. "0 0 * * *".
@hourly : Run once an hour, ie. "0 * * * *".
The shortcuts replace the time and date fields. @weekly runs every Sunday at 00:00. Just use
logrotate(8) was designed for this purpose. It does not have to be log files, it can be any file. You can set it up to run weekly at the specific time you want and give it the files using wildcard or exacting names. You can also compress and rotate so as to retain the superseded files up to some chosen number of rotations.
wouldn't just tossing a script it into cron.weekly on a Sunday and running it keep it running every Sunday too?
I only say this because I have a trim script tossed into weekly and it runs once a week. though I never marked the day I put it in there against when it actually runs. but it does run once a week, and I have not added it to a run job.
"Kind pilgrim, heed thee, now, the most-wise admonition given thee by rtmistler in reply #3!"
logrotate is a tool that was specifically designed to deal with the inevitable accumulation of "historical files of any sort." It can do a lot of other useful things, too.
But it is smart about doing it. rm is ... not.
Last edited by sundialsvcs; 05-01-2017 at 01:23 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.