Read from file then purge or archive.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from file then purge or archive.
# 1  
Old 08-09-2006
Read from file then purge or archive.

Hi All,
I have a root directory /tmp and I want to purge files or archive files in its subsequent subfolders.I listed the path of files I want to purge(archive) and the #of days.
(purge)
DAYS PATH
7 /tmp/arsenal/*
5 /tmp/chelsea/*

(archive?
the same as above but different folders

To purge I want to use

find $PATH -type f -mtime +$DAYS -exec rm {} \;

The problem now is, in order to do this,I need to first read the DAYS and PATH from the files which I am struggling to do.

I tried this

cat 'filestopurge.txt' | while read DAYS PATH
do
case $AGE in
*) find ........

Please dont forget that it will be read from a file filestopurge.txt

Please advise.

Regards,
Dougy
# 2  
Old 08-09-2006
Something like this ?
Code:
while read DAYS PATH
do
   find $PATH -type f -mtime +$DAYS -exec rm {} \;
done < filestopurge.txt

jean-Pierre.
# 3  
Old 08-09-2006
Hi Pierre,
Does your code take filestopurge.txt as the input file?I mean in read the path and days from it?

Thanks a lot
Dougy
# 4  
Old 08-09-2006
followup

I executed your script against the filestopurge.txt and got this:
./purgeam.sh
./purgeam.sh[4]: find: not found
./purgeam.sh[4]: find: not found
./purgeam.sh[4]: find: not found

the filestopurge.txt looks like this:
DAY PATH
90 /interface/backup/dbmig/tmp/*
100 /interface/backup/dbmig/*

Your script apparently read the DAY as 90 and the path, and executes the command.

Am I right?
# 5  
Old 08-09-2006
For each line of the file, the script read the two fields in the variables DAYS and PATH and execute the find command.

PATH is not a good choice for a variable because it is used by the shell.
Code:
while read DAYS ARCH_PATH
do
   find $ARCH_PATH -type f -mtime +$DAYS -exec rm {} \;
done < filestopurge.txt

If the header 'DAY PATH' is present in your file, it must be skipped:
Code:
while read DAYS ARCH_PATH
do
   [ "$DAYS" = "DAY" ] && continue # Edit: Correct Variable Name  
    find $ARCH_PATH -type f -mtime +$DAYS -exec rm {} \;
done < filestopurge.txt

Another way
Code:
tail +2 filestopurge.txt | \
while read DAYS ARCH_PATH
do
   find $ARCH_PATH -type f -mtime +$DAYS -exec rm {} \;
done

Jean-Pierre.

Last edited by aigles; 08-09-2006 at 03:24 PM..
# 6  
Old 08-09-2006
followup

Thanks Jean,
THe problem now, I got this error:Error in processing the argument DAYS. I thought probably, its unable to read the numbers and the path. I was thinking of using a case statement.What do you think?

Thanks
# 7  
Old 08-09-2006
Run your script with debug option to see the command that are executed
Code:
sh -x the_script

In the input file, remove the trailing '/*' from paths.


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Archive and purge the log file

Hi Unix Experts, I am new in this filed. I have assignment to Archive and purge the log file using shell scripts I tried I could not get the result please help me this. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log)... (1 Reply)
Discussion started by: johney1981
1 Replies

2. UNIX for Advanced & Expert Users

Purge MAil file

Hi, merry christmas. on AIX 6.1, the file /var/spool/mail/user, should/can be purged manually ? Any commande line to purge it ? Thanks. (2 Replies)
Discussion started by: big123456
2 Replies

3. Shell Programming and Scripting

Need a script or one-liner to purge lines from a file.

i all. This one sounds so simple, but I can't get it to work. I need to delete lines with certain keywords from a file. I have a file called defaultRules, with keywords: IPSEC_AH IKE_UDP IPMP_TEST_IFACE2 Then, I have another file called rules.txt with some rules: ... (10 Replies)
Discussion started by: BRH
10 Replies

4. Shell Programming and Scripting

Problem to read archive

Dear all, I have this archive: cat file.txt archive test 02 sequence 03 02length 52 archive test 02 sequence 04 02length 52 archive test 02 sequence 05 02length 52 teste arquivo 06 sequencia 08 06 length 54 teste arquivo 06 sequencia 09 ... (8 Replies)
Discussion started by: cewa67
8 Replies

5. Shell Programming and Scripting

Purge files and archive

Hi Friends, I have an urgent requirement. I have many files huge in size which has occupied almost the entire disk space. The files are not being moved to the archived folder. But at present I need to purge those files, new to shell scripting, not sure how to proceed. Eg. Directory... (3 Replies)
Discussion started by: unx100
3 Replies

6. Programming

read file from tar.gz archive

I want to write a c-program which reads a textfile from a tar.gz archive. How can I do it? (9 Replies)
Discussion started by: krylin
9 Replies

7. Shell Programming and Scripting

Read specific file from a zip archive without extracting

Hi All, I would like to extract specific file from a zip archive. I have a zip archive "sample.zip". sample.zip contains few text files and images... text1.txt, text2.txt, pic.jpg etc... I need to read specific file "text2.txt" from "sample.zip" WITHOUT EXTRACTING the zip file. ... (4 Replies)
Discussion started by: sridharg
4 Replies

8. Shell Programming and Scripting

script to archive and purge

Hi, I am writing a shell script for archive data from a table. The design is as follows. Step 1: Execute the select query and extract the data into a text file. Step 2: The primary key for this table is TRACKING_NUM, TRACKING_NUM_SUFFIX, TIMESTAMP_UPDATED. So These three fields will be read... (1 Reply)
Discussion started by: kmanivan82
1 Replies

9. Shell Programming and Scripting

shell script for archive purge

I am writing a shell script for Archive Purge for the table having rows < 1 year. The shell script has to extract the rows from the table and write those extracted rows to a text file. Then from the text file, each rows will be read and deleted by means of delete query one by one. The fields will... (5 Replies)
Discussion started by: regnumber
5 Replies

10. Shell Programming and Scripting

read list of filenames from text file, archive, and remove

I posted a week ago regarding this scripting question, but I need to revisit and have a few more questions answered.. User cfajohnson was extremely helpful with the archive script, but clarification on my part is needed to help steer the answer in a direction that works in this particular... (5 Replies)
Discussion started by: fxvisions
5 Replies
Login or Register to Ask a Question