cancel
Showing results for 
Search instead for 
Did you mean: 

help find and compress

SOLVED
Go to solution
viseshu
Frequent Advisor

help find and compress

Hi Guys ,
please help me with this

I need to take file from a path /home/abc/

· Get the date from the file example 20091008 from MasterIndex20091008_2.xml

· Then check if the date is 7days old or it is a month end(last day of month) or it is last day(Friday)of a week.

· If not above, then that file should be zipped .
6 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: help find and compress

Hi:

I'll give you some pointers.

Use 'find /home/abc -type f -mtime +7' to find files that are 7-days or older. If you truly want only 7-days, drop the "+".

You could use regular expressions to snip out the date from your filename or simply use 'cut' if you have a format that suggests what to isolate.

Dennis offered a nice 'awk' solution to a question you asked before. Of course, you very rearely assign points so no one knows if his solution enlightened you:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1336329

What's also noteworthy is that he used the 'cal' command to determine if the date was the last of the month --- exactly one of your requirements here.

For resolving whether or not a particular date is a Friday, you could test for a value of _five (5) as returned by:

# perl -MTime::Local -wle 'print +(localtime(timelocal(0,0,0,$ARGV[1],$ARGV[0]-1,$ARGV[2]-1900)))[6]' MM DD YYYY

...where you pass the MM, DD and YYYY values that you want to assess.

Regards!

...JRF...



viseshu
Frequent Advisor

Re: help find and compress

Sorry for not assigning points and Thanks for your inputs.
viseshu
Frequent Advisor

Re: help find and compress

Hi ,
I dont have perl compiler on my system. Can you suggest any approach using shel.
James R. Ferguson
Acclaimed Contributor

Re: help find and compress

Hi (again):

> I dont have perl compiler on my system. Can you suggest any approach using shel.

You should have Perl of some version even on very old HP-UX systems. That aside, you could use Clay's 'caljd' script to perform a multitude of manipulations. You can fetch a version from Merijn's site:

http://mirrors.develooper.com/hpux/

# ./caljd -w 10 16 2009
5

...the value of 5 returned signifies a Friday.

Regards!

...JRF...
viseshu
Frequent Advisor

Re: help find and compress

Thnks James that will be very helpful.
Need another clarification on 7 days old file.
When i fetch a date (yyyymmdd) from a file name (this will be diferent from date attached with the file), is it possible to find if that yyyymmdd is 7 or more old days old considering only weekdays?

Thanks in advance
James R. Ferguson
Acclaimed Contributor

Re: help find and compress

Hi (again):

> When i fetch a date (yyyymmdd) from a file name (this will be diferent from date attached with the file), is it possible to find if that yyyymmdd is 7 or more old days old considering only weekdays?

If I understand correctly, then the following applies:

'find()' has no concept of weekends. Time is measured in epoch seconds and when 'find()'s '-mtime' is used the units are the number of seconds in a 24-hour period measured from the file's modification time. For example, given that today is Oct 16, seven days ago it was Oct 9 and:

# find /path -type f -mtime 7

...will return files that were last modified Oct 8 or Oct 9 since the rule is that 'find' will return our files when the modification time subtracted from the initialization time is n-1 to n multiples of 24-hours. This is described in the manpages.

I suppose that you could "adjust" your criteria using nine (9) instead of (7) days as your 'find' window.

Regards!

...JRF...