FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 12-03-2010, 07:57 PM
Alejandro Rodriguez Luna
 
Default Total Number of conecctions

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@yahoo.com.mx

MSN: el_alexluna@yahoo.com.mx

GTalk: alexluna@gmail.com

Movil: 044-311-112-86-41

----------------------------------




*_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 08:16 PM
Ned Slider
 
Default Total Number of conecctions

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

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 08:18 PM
Robert Heller
 
Default Total Number of conecctions

At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list <centos@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 '
' '+'|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@yahoo.com.mx
>
> MSN: el_alexluna@yahoo.com.mx
>
> GTalk: alexluna@gmail.com
>
> Movil: 044-311-112-86-41
>
> ----------------------------------
>
>
>
> MIME-Version: 1.0
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
>

--
Robert Heller -- 978-544-6933 / heller@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/ www.asciiribbon.org -- against proprietary attachments



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 08:27 PM
 
Default Total Number of conecctions

Robert Heller wrote:
> At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list
> <centos@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 '
' '+'|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.

Why do people use awk without using it?
netstat -an | awk '{if ($0 ~ /tcp|udp/){ print $6;}END { print NF;}' gets
you the number of lines at the end. Or, to be more elegant,
netstat -an |
awk '{if ($0 ~ /tcp|udp/) {
array[$6] += 1;
}
END {
for ( i in array ) {
print i;
sum += array[i];
}
print sum;
}'

mark "me? like awk? yell at Larry Wall in '94 for proselytizing
perl in comp.language.awk?"

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 08:33 PM
 
Default Total Number of conecctions

Sorry, missed a close brace:

m.roth@5-cent.us wrote:
> Robert Heller wrote:
>> At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list
>> <centos@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 '
' '+'|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.
>
> Why do people use awk without using it?
> netstat -an | awk '{if ($0 ~ /tcp|udp/){ print $6;}END { print NF;}' gets
> you the number of lines at the end. Or, to be more elegant,
> netstat -an |
> awk '{ if ($0 ~ /tcp|udp/) {
> array[$6] += 1;
> }
}
> END {
> for ( i in array ) {
> print i;
> sum += array[i];
> }
> print sum;
> }'
>
> mark "me? like awk? yell at Larry Wall in '94 for proselytizing
> perl in comp.language.awk?"
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 08:46 PM
Alexander Dalloz
 
Default Total Number of conecctions

Am 03.12.2010 22:27, schrieb m.roth@5-cent.us:
> Robert Heller wrote:
>> At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list
>> <centos@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 '
' '+'|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.
>
> Why do people use awk without using it?
> netstat -an | awk '{if ($0 ~ /tcp|udp/){ print $6;}END { print NF;}' gets
> you the number of lines at the end. Or, to be more elegant,
> netstat -an |
> awk '{if ($0 ~ /tcp|udp/) {
> array[$6] += 1;
> }
> END {
> for ( i in array ) {
> print i;
> sum += array[i];
> }
> print sum;
> }'
>
> mark "me? like awk? yell at Larry Wall in '94 for proselytizing
> perl in comp.language.awk?"

Pretty correct. I hate those pipe orgies and awk usage where people just
use it to print out a specific field. Why piping grep output into awk
when awk itself can grep?

Though Mark, I feel you miss something in your awk script. It does not
print the value of each state.

LANG=C netstat -an | awk '/tcp|udp/ { array[$6] += 1; sum += 1 } END {
for ( i in array ) printf "%3s %s
", array[i],i; print sum }'

Alexander



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 09:00 PM
 
Default Total Number of conecctions

Alexander Dalloz wrote:
> Am 03.12.2010 22:27, schrieb m.roth@5-cent.us:
>> Robert Heller wrote:
>>> At Fri, 3 Dec 2010 12:57:59 -0800 (PST) CentOS mailing list
>>> <centos@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
<snip>
>>> <the above script> | awk '{print $1;}' | tr '
' '+'|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.
>>
>> Why do people use awk without using it?
>> netstat -an | awk '{if ($0 ~ /tcp|udp/){ print $6;}END { print NF;}'
>> gets you the number of lines at the end. Or, to be more elegant,
>> netstat -an |
>> awk '{if ($0 ~ /tcp|udp/) {
>> array[$6] += 1;
>> }
>> END {
>> for ( i in array ) {
>> print i;
>> sum += array[i];
>> }
>> print sum;
>> }'
>>
>> mark "me? like awk? yell at Larry Wall in '94 for proselytizing
>> perl in comp.language.awk?"
>
> Pretty correct. I hate those pipe orgies and awk usage where people just
> use it to print out a specific field. Why piping grep output into awk
> when awk itself can grep?

My point, exactly.
>
> Though Mark, I feel you miss something in your awk script. It does not
> print the value of each state.
>
> LANG=C netstat -an | awk '/tcp|udp/ { array[$6] += 1; sum += 1 } END {
> for ( i in array ) printf "%3s %s
", array[i],i; print sum }'

Or you could just
...END {
for ( i in array ) {
print i " " array[i];
}
print sum;
}
because I already did += 1 in the main body, so the contents are totalled
for that type.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 12-03-2010, 09:11 PM
Les Mikesell
 
Default Total Number of conecctions

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 ESTABLISHED

Personally, 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@gmail.com

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 01:21 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org