I have the need to know how many connection the server has, i run this command but i don't know how to sum all the results and get a final number. any ideas? netstat -an | grep -E 'tcp|udp' | awk '{print $6}' | sort | uniq -c | sort -n ?? 1 CLOSE_WAIT ?? 1 FIN_WAIT_2 ?? 1 LAST_ACK ?? 1 TIME_WAIT ?? 4 SYN_SENT ? 15 ? 37 LISTEN ? 44 ESTABLISHED ---------------------------------- Alejandro Rodriguez Luna Web: http://www.alexluna.org E-mail: el_alexluna at yahoo.com.mx MSN: el_alexluna at yahoo.com.mx GTalk: alexluna at gmail.com Movil: 044-311-112-86-41 ---------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20101203/dea01cba/attachment-0002.html>
On 03/12/10 20:57, Alejandro Rodriguez Luna wrote:> I have the need to know how many connection the server has, i run this command but i don't know how to sum all the results and get a final number. > any ideas? > > netstat -an | grep -E 'tcp|udp' | awk '{print $6}' | sort | uniq -c | sort -n > > 1 CLOSE_WAIT > 1 FIN_WAIT_2 > 1 LAST_ACK > 1 TIME_WAIT > 4 SYN_SENT > 15 > 37 LISTEN > 44 ESTABLISHED > >How about just counting the number of lines of output with 'wc -l': netstat -antu | wc -l
At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list <centos at centos.org> wrote:> > > > I have the need to know how many connection the server has, i run this command but i don't know how to sum all the results and get a final number. > any ideas? > > netstat -an | grep -E 'tcp|udp' | awk '{print $6}' | sort | uniq -c | sort -n > > ???? 1 CLOSE_WAIT > ???? 1 FIN_WAIT_2 > ???? 1 LAST_ACK > ???? 1 TIME_WAIT > ???? 4 SYN_SENT > ?? 15 > ?? 37 LISTEN > ?? 44 ESTABLISHED<the above script> | awk '{print $1;}' | tr '\n' '+'|sed 's/\+$//g'|bc The awk prints just the number, the tr replaces the newlines with +'s, the sed strips off the trailing + (from the last newline), and bc does the math.> > > > ---------------------------------- > > Alejandro Rodriguez Luna > > Web: http://www.alexluna.org > > E-mail: el_alexluna at yahoo.com.mx > > MSN: el_alexluna at yahoo.com.mx > > GTalk: alexluna at gmail.com > > Movil: 044-311-112-86-41 > > ---------------------------------- > > > > MIME-Version: 1.0 > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos > >-- Robert Heller -- 978-544-6933 / heller at deepsoft.com Deepwoods Software -- http://www.deepsoft.com/ () ascii ribbon campaign -- against html e-mail /\ www.asciiribbon.org -- against proprietary attachments
On 12/3/2010 2:57 PM, Alejandro Rodriguez Luna wrote:> I have the need to know how many connection the server has, i run this > command but i don't know how to sum all the results and get a final number. > any ideas? > > netstat -an | grep -E 'tcp|udp' | awk '{print $6}' | sort | uniq -c | > sort -n > > 1 CLOSE_WAIT > 1 FIN_WAIT_2 > 1 LAST_ACK > 1 TIME_WAIT > 4 SYN_SENT > 15 > 37 LISTEN > 44 ESTABLISHEDPersonally, I'd only call 'ESTABLISHED' state a connection. The other states might still have a socket tied up at your end, but you don't really know what's going on at the other. -- Les Mikesell lesmikesell at gmail.com