SHELL SCRIPT TO FIND THE TOTAL DATA TRANSFERED OVER NETWORK FROM SOURCE TO DESTINATION IN LINUX

Here is a one liner to calculate the total bytes transfered from one server to another in linux. This is the results taken from tcpdump output file

grep 'length' tcpoutput|awk '{print $17}'|cut -f 1 -d ')'|grep -Ex '[0-9]+'|awk '{sum +=$1;}END{print sum;}'|xargs -I {} expr {} / 104857

All the output from tcpdump are redirected to a trace file

tcpdump -i enp0s3 -vvv > tcpoutput

Length column of the output has been filtered and added up to get the total bytes output

[oracle@dp ~]$ grep 'length' tcpoutput|awk '{print $17}'|cut -f 1 -d ')'|grep -Ex '[0-9]+'|awk '{sum +=$1;}END{print sum;}'|xargs -I {} expr {} / 1048576 && echo "MB"
637
MB

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s