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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2006
kayarsenal kayarsenal is offline
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
  #2 (permalink)  
Old 08-25-2006
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137

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-25-2006 at 03:05 AM.. Reason: add code tags...
Closed Thread

Bookmarks

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 11:55 AM.


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