ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hpunix.
I have logfiles in /archive_store directory which are deleted by below script once the directory is 90 percent full.
What I want to do is, before deleting each logfile, I want to make sure they are at least 1 day older than current time.
If they are not, the script should terminate.
Time of the each log can be seen before ".Z" prefix.
I have to pickup that time and compare it with current time.
I aprreciate any help.
----------------------------------------------------
ls /archive_store
If all of the files in that directory are subject to deletion then this would work.
Code:
find /archive_store -type f -atime +1 -exec rm {} \;
If all of the files to be deleted have names that end in Z and if there are other files that you need to keep that have names that do NOT end in Z then this would work.
Thanks for your suggestion but I dont want to delete.
The following script suits my needs, however as I mentioned above it doesnt work in below scnerio:
LOGDAY=20101129
TODAY= 20101201
Difference is 72, which is not correct, since these are dates.
To make a proper comparison, you could get both dates into perl and use a perl script to calculate the date and time difference (perl would be better suited to that than bash).
By the way, if you find a post helpful, click the scales icon to the left of the post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.