The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting files after the creation of a tar archive Minguccio75 UNIX for Advanced & Expert Users 5 02-13-2007 06:26 AM
Archive script old files kayarsenal Shell Programming and Scripting 1 08-25-2006 01:46 AM
Archive files older than 30days dsravan Shell Programming and Scripting 8 07-26-2006 04:52 PM
script to archive all the log files tintedwindow Shell Programming and Scripting 0 06-13-2006 10:51 PM
tar archive with .Z files Kun2112 UNIX for Dummies Questions & Answers 3 08-05-2005 09:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-18-2006
kayarsenal kayarsenal is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 48
Archive files

Hi All,
I wrote this script:
Code:
#!/bin/ksh
while read DAYS ARCH_PATH
do
  cd $ARCH_PATH
  find . \( -type d ! -name . -prune  \) -o  -type f -mtime +$DAYS -exec tar -cv
f kay_`date +%d%m%y%H%M`.tar {} \;
  cd -
done < filestoarchive.txt
The problem is, in a folder of 7files, I would expect to have 7files archived, but the script only archives only 1 file.

Please advise.
  #2 (permalink)  
Old 08-18-2006
kayarsenal kayarsenal is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 48
followup

Hi,
Has anyone seen this before pls? I tried to archive some files and I get this message:
tar: cannot stat xxx.ddmmyy.tar NOT DUMPED

Thanks
  #3 (permalink)  
Old 08-18-2006
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
You can build the list of files to archive and use the -L option of tar :
Code:
#!/bin/ksh
while read DAYS ARCH_PATH
do
  cd $ARCH_PATH
  find . \( -type d ! -name . -prune  \) -o  -type f  -mtime +$DAYS | sed "s+^.+$PWD+" > filelist
   cd -
done < filestoarchive.txt
tar -cvfL  kay_`date +%d%m%y%H%M`.tar filelist
Jean-Pierre.

Last edited by aigles; 08-18-2006 at 12:21 PM..
  #4 (permalink)  
Old 08-18-2006
kayarsenal kayarsenal is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 48
followup

Hi,
Its you again.Thanks a lot. I executed this code but got only the list of files in the filelist file but no .tar file in the folder. Please why do we have 'cd -' in the code? Whats the use of that?

Regards,
Kay
  #5 (permalink)  
Old 08-18-2006
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
cd - returns to the previous directory.
I have modified the script a little bit.
Code:
#!/bin/ksh
FileList=$PWD/filelist
while read DAYS ARCH_PATH
do
  cd $ARCH_PATH
  find . \( -type d ! -name . -prune  \) -o  -type f  -mtime +$DAYS | sed "s+^.+$PWD+" > $FileList
  cd -
done < filestoarchive.txt
tar -cvfL  kay_`date +%d%m%y%H%M`.tar $FileList
Jean-Pierre.
  #6 (permalink)  
Old 08-18-2006
kayarsenal kayarsenal is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 48
followup

By the way, I removed the L option, but it tarred only the filelist,where as it should tar the files in the filelist. Did u mean small L (l) instead of L. I tried that too but still, it tarred only the filelist file.
  #7 (permalink)  
Old 08-18-2006
kayarsenal kayarsenal is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 48
followup

Hi
Still I believe the final command
Code:
tar -cvfL  kay_`date +%d%m%y%H%M`.tar $FileList
still tars the filelist. I reckon it should be passed to the tar command just like we did with the filestoarchive.txt. Sorry to bother you, did you try it?

For example: I wanted it to archive any files in folder ARSENAL that are older than 40days. In the filestoarchive, I have



40 /path/Arsenal

Assuming there are 5files older than 40days, I should have the tar file with the date, and better would be to remove the files.

Thanks
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0