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 03: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 Search this Thread Display Modes
  #8  
Old 08-18-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
modified version of the script :
Code:
#!/bin/ksh

#
# Build list of files to archive
#

FileList=$PWD/filelist
> $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 all selected files using builded list
# For some Unix flavour, the -L option is replaced by another option (-I, not sure)
#

tar -cvfL  kay_`date +%d%m%y%H%M`.tar $FileList

#
# Delete all tared files only if tar successful
#

if [ $? -eq 0 ]
then
   while read file
   do
      rm -f $file
   done < $FileList
fi
First read tar man page to determine the right option (-L or -I).
Execute the script and verify the list of selected files in filelist.
List contents of producted tar file (using tar -tvf).


Jean-Pierre.
Reply With Quote
Forum Sponsor
  #9  
Old 08-21-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

Hi Jean,
Heres the output of the code?
Code:
sh -x tryarchive.sh
+ FileList=/GUNNERPATH/filelist
+ 1> /GUNNERPATH/filelist
+ 0< filestoarchive.txt
+ read DAYS ARCH_PATH
+ cd /GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS.10
+ sed s+^.+/GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS
.10+
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +160
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ cd /GUNNERPATH/etltest/LINKS/packed/Arsenal
+ sed s+^.+/GUNNERPATH/etltest/LINKS/packed/Arsenal+
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +160
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ cd
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +
+ sed s+^.+/GUNNERPATH+
+ 1>> /GUNNERPATH/filelist
+ cd -
/GUNNERPATH
+ read DAYS ARCH_PATH
+ date +%d%m%y%H%M
+ tar -cvfL kay_2108060833.tar /GUNNERPATH/filelist
tar: L: unknown option
tar: usage  tar [-]{txruc}[eONvVwAfblhm{op}][0-7[lmh]] [tapefile] [blocksize] [[
-C directory] file] ...
+ [ 1 -eq 0 ]
The filetoarchive is:
160 /GUNNERPATH/etltest/LINKS/hashfiles/XA_ERRORS.10
160 /GUNNERPATH/etltest/LINKS/packed/Arsenal

I have a question here please:
1.tar -cvfL kay_2108060833.tar /GUNNERPATH/filelist - does this not tar just the filelist in the GUNNERPATH? the filelist obviously would contain what I have in filetoarchive.
2.Is it OK to use + with sed command? I thought sed should be with / eg sed 's/xxx/yyy/g' etc. I may be wrong.

Thanks Jean

It seems not to be working.
Reply With Quote
  #10  
Old 08-21-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

One mor ething please...The script is not taring but it removes the files it should tar. The option is -l not L. Also it removes some files that are not even in the folder it should tar.For example, it removes all the files in the HOME directory from where its being executed.
Reply With Quote
  #11  
Old 08-21-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

The script is only taring /interface/dashboard/users/aolukayo/filelist but not the contents(path) in fileset. Worse is, it removes all the files in the paths in the fileset file.
Reply With Quote
  #12  
Old 08-21-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

Sorry Jean,
Its me again, I think it would be better to FIND the files older than some date,and tar it.
Also the tarred file should be in the folder where it gets the files its tarring.Presently,the tarred files are in the home directory.
Cheers
Reply With Quote
  #13  
Old 08-21-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Seems that your version of tar does'nt support an option that permits to get names of files to archive from a file.
For tar GNU version, the option is -T or --files-from
For Aix, the option is -L

In your original script, replace the c mode (creates a new archive ) by the r mode (writes the files to the end of the
archive.
Code:
#!/bin/ksh
while read DAYS ARCH_PATH
do
  cd $ARCH_PATH
  find . \( -type d ! -name . -prune  \) -o  -type f -mtime +$DAYS -exec tar -rvf kay_`date +%d%m%y%H%M`.tar {} \;
  cd -
done < filestoarchive.txt
Jean-Pierre.
Reply With Quote
  #14  
Old 08-21-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
followup

This is the output:
Code:
 date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime +5 -exec tar -rvf kay_2108061554.tar {} ;
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
tar: cannot open kay_2108061554.tar
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
+ cd
+ date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime + -exec tar -rvf kay_2108061554.tar {} ;
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
+ cd
+ date +%d%m%y%H%M
+ find . ( -type d ! -name . -prune ) -o -type f -mtime + -exec tar -rvf kay_2108061554.tar {} ;
+ cd -
/interface/backup
+ read DAYS ARCH_PATH
The other problem with this is, even when it tars the files,assumming there are 5files is a path, it tars only one of the files.Ideally,it should take all the files in the folder that is older than the date specified,and put them in One dot.tar file.

I thought of reading the files in a folder and save it to some file:
Code:
find . \( -type d ! -name . -prune  \) -o  -type f  -mtime +$DAYS | \
  sed "s+^.+$PWD+" >>FileList
Then cat the file,read from the cat output,then perform the tar on it.See the full code below.Its not working though.probably u could spot the mistake.

Code:
#!/bin/ksh

#
# Build list of files to archive
#

#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 all selected files using builded list
#

for i in `cat $FileList`
do
tar -cvfl  kay_`date +%d%m%y%H%M`.tar $i |gzip >/$PWD/kay_`date +%d%m%y%H%M`.tar.gz
done

#
# Delete all tared files only if tar successful
#

#if [ $? -eq 0 ]
#then
#   while read file
#   do
#      rm -f $file
#   done < $FileList
Thanks a lot
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:30 PM.


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

Content Relevant URLs by vBSEO 3.2.0