I'm trying to make a script (using Perl, but it isn't necessary) that will only count the number of Established, Time\_Wait, and Closed\_Wait connections on a system and print them in terminal. So far I've figured out that I can use :

```
netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n

```

in order to print all of the connections, but when I run this from a script it will not print in terminal and it also gives me some connections that I am not looking for such as Listen and Foreign. The reason why it must only show Established, Time\_Wait, and Closed\_Wait is because the script is being used by a monitoring program that will fail if any other connection types show up. Can anyone make a suggestion? Thanks!