The UNIX and Linux Forums  

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 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 02:26 AM
Archive script old files kayarsenal Shell Programming and Scripting 1 08-24-2006 10:46 PM
Archive files older than 30days dsravan Shell Programming and Scripting 8 07-26-2006 01:52 PM
script to archive all the log files tintedwindow Shell Programming and Scripting 0 06-13-2006 07:51 PM
tar archive with .Z files Kun2112 UNIX for Dummies Questions & Answers 3 08-05-2005 06:42 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-18-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Stumble this Post!
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-18-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Stumble this Post!
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
Reply With Quote
  #3 (permalink)  
Old 08-18-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
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 09:21 AM.
Reply With Quote
  #4 (permalink)  
Old 08-18-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Stumble this Post!
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
Reply With Quote
  #5 (permalink)  
Old 08-18-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
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.
Reply With Quote
  #6 (permalink)  
Old 08-18-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Stumble this Post!
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.
Reply With Quote
  #7 (permalink)  
Old 08-18-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Stumble this Post!
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0