Print fields to a file based on protocol type from netstat.
Hi Guys,
I am trying to fetch the network connections on Centos host and write to a log. However, as UDP doesnt have a connection state, the report has a problem with displaying data as tcp has a state in the corresponding field. I am trying to handle this using below:-
if [$(netstat -anputw | awk '{print $1}')=="tcp"] then
netstat -anputw | awk '{print $1,",",$4,",",$5,",",$6,",",$7}' >> $HOME/MyLog/connections_$HOSTNAME.csv
elif [$(netstat -anputw | awk '{print $1}')=="udp"] then
netstat -anputw | awk '{print $1,",",$4,",",$5,",",",",$6}' >> $HOME/MyLog/connections_$HOSTNAME.csv
fi
So, I am trying to see wherever the protocol from netstat command is tcp, it prints the required fields and when its udp, then the corresponding state field should be empty.
However, it doesnt work. Any idea what could be wrong here?
|