Temporary files and rm

Hello everyone,
I am creating a temporary file in my ksh by using something file
filetemp=filetemp.$$
Later on in my script I write to the file $filetemp by 'cat'ing to it.
Then in the script I am doing a 'less' on the file to view it.
At the end of the script I issue a rm $filetemp 2> /dev/null .
I am experiencing an issue that I would like to have explained.
Most of the times the file is deleted properly. Once in a while, though, the file is still there after I exit my script.
I cannot tell if it is related to the file being large or small or if it is tied to the amount of time the file stays open under the 'less' command.
Any ideas?
Maybe there is a better way to deal with temp files?
Any suggestions or advice will be greatly appreciated.
Thanks.

u can always use mktemp to create temp files

and to delete the file at the end

just do

trap '/bin/rm -f $file' 0 1 3

I do not seem to have mktemp on AIX.

Well, the first thing you should do is change 'rm $filetemp 2> /dev/null' to 'rm $filetemp 2> somefile' so you can capture the error message and interrogate what rm is producing in order to find out why it is not removing the file. This may give you a clue as to what is happenning.

Sam

maybe your script is receiving some kind of kill signal and dieng before the rm