Link to home
Start Free TrialLog in
Avatar of RPIIT
RPIIT

asked on

Need a shell script to gzip files by date.

I need a shell script that can compress files using gzip by modified date.
So orignally I have some 108,000 files dated from 01-01-2005 to current date. I would like the outcome to be a collection of zip files for each month and year, so I have one zip file that contains all my original files with modified dates ranging from 01-01-2005 to 01-31-2005. Then I would have another zip file for all my original files with modified dates ranging from 02-01-2005 to 02-29-2005 and so on. I would also like the oringal files deleted after sucessfull compression.

--
Jesse
Avatar of Tintin
Tintin

Do the file names have the date in them, or do you have to rely on the modification date?
Avatar of RPIIT

ASKER

Filenames are random numberic values, so I would have to rely on the modification date.

--
Jesse
Do you want the output to be a zip file or tar gzip file?
Avatar of RPIIT

ASKER

A zip file that windows or winzip would be perferable but iif need by I could use a tar gzip file.

--
Jesse
 find . -type f -printf "echo '%p' >> /tmp/T/%Ay%Am\n"|sh
  ls /tmp/T/ | awk '{printf("tar cf %s.tar `cat %s`\n",$1,$1)}'|sh

for testing simply omit the final  |sh
you may encounter problem with your shell, such as "argument too long", then you need to make smaller file list, for example by using  %Ay%Am%Ad instead of %Ay%Am
Avatar of RPIIT

ASKER

I will test this when I get back in the office on Tuesday.

--
Jesse
Avatar of RPIIT

ASKER

Ok, I hope I changed the directories to match my needs as best I understand. I am executing the following as a .sh file

find /ifs/backup/QA/Snapfish -type f -printf "echo '%p' >> /ifs/backup/QA/tmp/T/%Ay%Am\n"|sh
ls /ifs/backup/QA/tmp/T/ | awk '{printf("tar cf %s.tar `cat %s`\n",$1,$1)}'

when run I get the following result.

RPISAN-5# ./xml.sh
find: -printf: unknown option
: command not found
RPISAN-5#
hmm, Linux uses Gnu find, usually which has -printf option
What system are you on?
   uname -a
Avatar of RPIIT

ASKER

I assume it's a modified distro made by Isilon.
uname -a gives me
Isilon OneFS RPISAN-5 v3.5.2 i386
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RPIIT

ASKER

Unfortunatly due to staffing issues I no longer have any time to work on this project. I thank you greatly for your help and applogize for my tardy response.