How to get netstat stats on interval (Linux)
search cancel

How to get netstat stats on interval (Linux)

book

Article ID: 47922

calendar_today

Updated On: 02-14-2018

Products

DX Unified Infrastructure Management (Nimsoft / UIM)

Issue/Introduction

Introduction

At times when troubleshooting probes, especially hub probe, you might be asked to get netstat looking for certain states e.g FIN_WAIT_2. The following script runs through cron every minute to collect netstat output.




Procedure

1- Create a script with following contents:

#!/bin/bash
DATE=`date`
CMD=$(netstat -tnl)
ARG=" -tn | grep FIN"
LOG=/nimsoft/netstats.log
?
echo ?"--------------------------------------" >> $LOG
echo $DATE >> $LOG
/bin/netstat -an |grep FIN >> $LOG
echo ?"--------------------------------------" >> $LOG
echo >> $LOG
?
2- Make script executable - assuming script name is get_netstats.sh
# chmod +x?get_netstats.sh

3- Install in cron
# crontab -e

4- Enter in edit mode and enter following
*/1 ? ? * ? ? ? * ? ? ? * ? ? ? * ? ? ? /root/get_netstats.sh

5- Save and exit editor

Environment

Release:
Component: CAUIM