Script removes itself

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 :frowning:

#!/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

The xxx.txt has this format.

DAYS PURGE_PATH
7 /A/B
....
....

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?

How do u mean run "touch"?

Thanks

put

touch -m scriptfilename

in your script befor rm command.
i guess you are familiar with touch command time format

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.

cd command may be creating the problem.path in input file is absolute path
if not then try by giving absolute path.