recovering deleted file held open by apache?

view story

http://unix.stackexchange.com – suppose an apache log file gets deleted but its held open by apache then this is what i am doing. pid=$(lsof | grep text.txt | awk '/deleted/ {print $2}') fd=$(lsof | grep text.txt | awk '/deleted/ {print $4}' | grep -oE "[[:digit:]]{1,}") cp /proc/$pid/fd/$fd directorytobecopied/testfile.txt this is what i am doing to recover the file and put it back where it was. is there any simpler way of doing this because above code doesn't look good. and furthermore how do i know from where the file was deleted(directorytobecopied) so that i don't have to manually ask somebody where the file was loc (HowTos)