I have a script that reads from a file and deletes all files in tha path specified in the file.The problem,however, is the script also deletes itself from the home directory where I run it
#!/bin/ksh
while read DAYS PURGE_PATH
do
cd $PURGE_PATH
find . \( -type d ! -name . -prune \) -o -type f -mtime +$DAYS -exec rm {} \;
cd -
done < xxx.txt
Try to keep scripts out of the paths where you purge files. If you must keep it there, then why not have the script run 'touch' to update the timestamps on itself before it enters the while loop?
Hi All,
I think I asked the question wrongly. The point is, the script deletes all the file in the path where I am running it which it shouldnt as the path is not the text file(xxx.txt) where it reads from.
So its not just the script itself that gets deleted, but also the files in the path where the script is located.