Archive script old files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Archive script old files
# 1  
Old 08-24-2006
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  
Old 08-25-2006
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. Shell Programming and Scripting

Need command/script to archive files older than

I need to find a way to archive all files older than a given date but there are some conditions that are making it difficult for me to find the correct command: Linux based system (RH5) there are multiple layers of directory depth I need to search each file should be tar'd in it's original... (1 Reply)
Discussion started by: KaosJedi
1 Replies

3. Shell Programming and Scripting

Check files and archive the files using sftp

Hi, I have to check the files in another server using sftp to do that, below is the code i am going with #!/bin/bash export SRC_FOLDER=$1 export ARC_FOLDER=$2 HOST=as07u3456 USER=relfag sftp ${USER}@${HOST} <<EOF cd $SRC_FOLDER/DSCOR ls bye EOF echo "done" whatever the files i... (8 Replies)
Discussion started by: ursrami
8 Replies

4. Shell Programming and Scripting

Script to Archive Files from Subdirectories

Hello, I have a CentOS server that contains a 'storage' directory. Within that directory, there could be any number of subfolders (all with unique names that match usernames). Under each username folder, there are two additional folders: db and files /STORAGE/user1/db/... (3 Replies)
Discussion started by: JasonH
3 Replies

5. UNIX for Dummies Questions & Answers

How to archive old files from the recently added 10 files?

Hi there, I am very new to unix and having trouble with a fairly simple statement: cd /user ls -t -c1 | sed -ne '11,$p' | mv xargs archive/ What I want the code to do is sort all files in a directory by timestamp, select all of the files after the 10th file, and then move those files... (3 Replies)
Discussion started by: DSIReady
3 Replies

6. Shell Programming and Scripting

script assistance needed - create an archive of INI files

First and foremost - me != unix bubba. Here is the situation. We have a box with data AND settings in the same directory path. (Data files aren't in the SAME directories as settings.) I need a script that generates a tarred-up archive of only the INI files with the directory structure. We... (2 Replies)
Discussion started by: hindesite
2 Replies

7. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

8. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

9. Shell Programming and Scripting

Script to archive log files:Urgent Help required

I have no prior knowledge of Unix shell scripting,but my requriment demands to wrie a script that do fallowing things. 1.Delete older than one year log files 2.Moves files in to the directories as YYYYMM wise. 3.If files in $LOGDIR older than n=2 months tar and move them to $ARCHIVEDIR... (5 Replies)
Discussion started by: vamsx
5 Replies

10. Shell Programming and Scripting

script to archive all the log files

is there a way to write a script and run with a cron job which archives all the *.log files into .tar.gz. :eek: (0 Replies)
Discussion started by: tintedwindow
0 Replies
Login or Register to Ask a Question