![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Something like this ?
Code:
while read DAYS PATH
do
find $PATH -type f -mtime +$DAYS -exec rm {} \;
done < filestopurge.txt
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
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
Code:
tail +2 filestopurge.txt | \
while read DAYS ARCH_PATH
do
find $ARCH_PATH -type f -mtime +$DAYS -exec rm {} \;
done
Last edited by aigles; 08-09-2006 at 11:24 AM. |
|
#6
|
|||
|
|||
|
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
|
||||
|
||||
|
Run your script with debug option to see the command that are executed
Code:
sh -x the_script Jean-Pierre. |
||||
| Google The UNIX and Linux Forums |