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
File Archive Script KeesH Shell Programming and Scripting 10 06-09-2008 08:11 AM
Purge files based on timestamp avl in file name sureshg_sampat Shell Programming and Scripting 3 02-29-2008 08:28 AM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 06:56 PM
Updating a File in a Zip Archive dbridle AIX 6 09-27-2006 12:29 PM
read file from tar.gz archive krylin High Level Programming 8 06-13-2003 08:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-09-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
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
Reply With Quote
Forum Sponsor
  #2  
Old 08-09-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
Something like this ?
Code:
while read DAYS PATH
do
   find $PATH -type f -mtime +$DAYS -exec rm {} \;
done < filestopurge.txt
jean-Pierre.
Reply With Quote
  #3  
Old 08-09-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
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
Reply With Quote
  #4  
Old 08-09-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
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?
Reply With Quote
  #5  
Old 08-09-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
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 11:24 AM.
Reply With Quote
  #6  
Old 08-09-2006
Registered User
 

Join Date: Aug 2006
Posts: 48
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
Reply With Quote
  #7  
Old 08-09-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
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.
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:29 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