Tuesday, 17 November 2015

PERL SCRIPT for killing CLOSE_WAIT

Some time our application gets chocked because of large number of connection in COSE WAIT state, In such case there is only way to get rid of it by closing application, but in production we cann't kill our application this frequently, so here is a hack I come accross for it.

Ultimate solution :: optimise and find reason in your application.

#!/bin/bash
netstat -tulnap | grep CLOSE_WAIT | awk '{print $4,$5}' |  sed 's/:/ /g' | awk '{print $2, $3, $5, $6}'|  while read line; do
        echo $line
        perl kill_cw.pl $line;
done


wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/perl-Net-RawIP-0.25-1.el6.rf.x86_64.rpm
wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/perl-Net-Pcap-0.16-1.el6.rf.x86_64.rpm
wget http://www6.atomicorp.com/channels/atomic/centos/6/i386/RPMS/perl-NetPacket-0.41.1-1.el6.art.noarch.rpm

rpm -Uvh  perl-Net-RawIP-0.25-1.el6.rf.x86_64.rpm
rpm -Uvh perl-Net-Pcap-0.16-1.el6.rf.x86_64.rpm
yum install perl-Net-Pcap

rpm -Uvh  perl-NetPacket-0.41.1-1.el6.art.noarch.rpm

(http://pkgs.org/centos-6/atomic-i386/perl-NetPacket-0.41.1-1.el6.art.noarch.rpm.html)