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
Archive large debug files without cp firdousamir Shell Programming and Scripting 5 04-08-2008 06:56 AM
Archive files kayarsenal Shell Programming and Scripting 13 08-21-2006 08:01 AM
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
  #1  
Old 08-24-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
Archive script old files

Hi All,
Im trying to write a script to archive files based on the date the files were created.
For example, if a group of files were created on 23rd August,I would have 230806.tar. I have a problem,I want the script to read a separately created file(readarchive.txt) to look for the path to archive.It reads the days(after how many days to archive files) and the path.I am not able to figure out how to pass in the readarchive.txt.
Heres the script
Code:
#!/bin/ksh

BIN=/Gunner/users/Arsenal/tarfiles

age=$1
directory="$2"

[ "$directory" = "" ] && directory=.

cd "$directory" || exit 1

from=`$BIN/today -$age`

ls -rt | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' | \
while read d t f
do
   [ -d $f ] && continue
   opt=u
   [ -w $d.tar ] || opt=c
   tar ${opt}f $d.tar $f && touch -r $f $d.tar && rm -f $f
done
Note:dttmfilter and today a c program!The program is working fine,it does exactly what I want it to do,but only when I manually copy the script to the folder I want to archive the files.Now I need to pass readarchive.txt which looks like this:

20 /gunner/chelsea (means archive all files in this folder after 20days) how do I include this in the program?

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 08-24-2006
jambesh's Avatar
Registered User
 

Join Date: Aug 2006
Location: Pune,India
Posts: 118
Code:
while read d t f
do
   [ -d $f ] && continue
   opt=u
   [ -w $d.tar ] || opt=c
   tar ${opt}f $d.tar $f && touch -r $f $d.tar && rm -f $f
done <readarchive.txt

I guess you want to read from readarchive.txt file using this while loop ??
at the end of done add <filename so that it will read line by line from that file and assigned it to the variable d t f

Last edited by blowtorch; 08-24-2006 at 11:05 PM. Reason: add code tags...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:36 AM.


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