How to know which process is causing the closed_wait?

I do have a friend who have this script already but lost it. Can you please help to give me a script that can capture the closed_wait on the stack and identify which process using it. I am thinking of using netstat and rmsock.

You could run netstat and then run lsof with -i option:

lsof -i [ipv4/ipv6][protocol][@hostname|hostaddr][:service|port]

Check lsof manual for further reference.

As you know, the first thing that you have to do before running code/script is to take a backup of that, its a fragile world. Wasn't that done?