If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > script with selection date for tar

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-08, 09:50
sant sant is offline
Registered User
 
Join Date: Sep 2003
Posts: 19
script with selection date for tar

Hello

I need a little help in my installation. We need make a tar all days with a directory with many files to selected for a date. I trying execute this command in a script

find /tmp/files/* -mmin +1440 -a -type f -exec tar -cf /tmp/comp.Z {} \;

it's running ok, but only contain one file into the comp.Z

Any know what is my problem?

If any know other method for make this, it's welcome.

Thank you
Reply With Quote
  #2 (permalink)  
Old 02-04-08, 16:31
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
-exec ... {} will run the command for each file that was found again. Thus, one "tar cf" will overwrite the tar file produced for the previous file. I would do this instead:
Code:
find /tmp/files/* -mmin +1440 -a -type f | xargs tar -cf /tmp/comp.Z
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 02-05-08, 02:12
sant sant is offline
Registered User
 
Join Date: Sep 2003
Posts: 19
Now it's work ok. I have still a lot of to learning

thank you for your help
Reply With Quote
  #4 (permalink)  
Old 02-05-08, 04:59
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you use the approach I posted above, you will run into problems as soon as a file name containing spaces is encountered. (You have the same problem in your original script as well, btw.) If you stick with "find" only, you should put double-quotes around the {}.

What would be a good idea is to use the -r or -u options to append files to an archive:
Code:
find /tmp/files/* -mmin +1440 -a -type f -exec tar uf comp.tar -uf "{}" \;
p.s: "tar" does not create a compressed file (extension .Z) unless you tell it to do so with the option -Z.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On