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
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.
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?
Most importantly Pierre,There could be a problem.
In a directory structure like
A|
-B
-C|
-D
Should I have in the filetopurge.txt /A/ and run the purgeam.sh file, then its purges automatically B,C and D since its recursive. THe problem now is,I might want to archive C i.e not purge the files,there will be situations whereby I need to archive a subfolder of a folder I have in filetopurge.txt(in this case,subfolder C). How do I go about it?
I considered having two text files, filestopurge.txt and filestoarch.txt,but this obviously would work, because in filestopurge,I would have:
7 /A and filetoarch.txt would be 5 /A/C .
After running filestopurge.sh, C would be gone.
Except the last question I asked.I am able to purge files now, but the script purges everything,even the ones I want to archive because its recursive and purges even the subfolders of the root directory. How do I escape this?