INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Archive old files more than a month in unix/solaris

Archive old files more than a month in unix/solaris

(OP)
Hi,

I have files concatenated with day of the year in a folder.
Say as
Jan 1st - aaa.001.txt
Feb 3rd - aaa.034.txt etc.
which I get with `date +%j`
I now need to archive files older than a month. my program works for forward dates other than January.
Being in Feb, I can delete files older than 30 day by taking few constant values in variables and negating with current date value.
However, being in Jan, my approach fails to archive last year's data. i.e. 335 --> 365.

Note: the script should run when ever we trigger and it should ensure to retain 1 month's data and delete rest of the old files.

Please help. Thanks in advance.

I can paste my code copy if required.

RE: Archive old files more than a month in unix/solaris

Something like this maybe?

CODE

#!/bin/ksh

typeset -Z3 DAY=$(date '+%j')

print "Today's day-of-year: ${DAY}"

typeset -Z3 PREV=$(( (365 + DAY - 30) % 365 ))

print "One month ago: ${PREV}\n"

DAY=15

print "For DOY = ${DAY}"

PREV=$(( (365 + DAY - 30) % 365 ))

print "One month prior: ${PREV}" 

Output is...

CODE

Today's day-of-year: 034
One month ago: 004

For DOY = 015
One month prior: 350 

Of course you'd need to add adjustments for leap year, but this approach will get you 30 days prior to any day-of-year.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close