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