Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need helping finding a file out of a tarball by date

Status
Not open for further replies.

xenolith

ISP
Mar 4, 2002
51
Im not sure if this is possible, Im thinking I may need something more powerful than regular shell script to do this. I backup RADIUS detail records weekly in an archive directory.
They are placed in:
archive/030402-031002/030402-031002.details.tar.gz
archive/031102-031702/031102-031702.details.tar.gz
and so on.

I need to pull certain files out of each but I only need the files from the previous month starting on the 13th through the 12th of the current month.

Any insight on how to go about this?

Thanks,
Josh
 
[tt]tar tvf file[/tt] will produce an ouput similar to [tt]ls -l[/tt], eg:
Code:
$ touch -t 199912251200 a
$ touch -t 200203131200 b
$ tar cf TAR.tar a b
$ tar tvf TAR.tar
tar: blocksize = 4
-rw-rw-r-- 562/28       0 Dec 25 12:00 1999 a
-rw-rw-r-- 562/28       0 Mar 13 12:00 2002 b
So you could use something like the following to get your subset of files:
Code:
tar tvf TAR.tar 2>/dev/null | awk -v month=`date +%b` '
$4 == month && $5 ~ /(12|13)/ { print $NF }'
Cheers, Neil
 
Sorry
Just noticed you wanted from 13th of previous month to 12th of this month.
You can still use the [tt]tar tvf[/tt] method, but the awk script becomes a lot more complex :-(
Happy coding, Neil
 
Actually after a few hours of racking my brain Ive gotten pretty close to doing what I needed to do. I created test files to work with.

-rw-r--r-- 1 root root 0 Feb 1 12:00 bad0201
-rw-r--r-- 1 root root 0 Feb 20 12:00 good0220
-rw-r--r-- 1 root root 0 Mar 1 12:00 good0301
-rw-r--r-- 1 root root 0 Mar 31 2002 bad0331

Running,
ls -l | awk -v prevmonth=`date --date='1 month ago' +%b` -v curmonth=`date +%b` '$6 == prevmonth && $7 >= 13 || $6 == curmonth && $7 <= 12 {print $NF}'

will only return the good filenames so Im close to doing what I need to do.

I definately appreciate the help Neil, its gotten me on a good route!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top