Sungju's Slow Life

Personal journal

[BASH] Check dropped RX packets

This is a simple bash script to check whether NIC is dropping packets or not. It works with only one NIC card at one time because there’s possiblity that packet can go through another NIC.


NET_ON_LIST=`ifconfig | grep "Link encap:Ethernet"`

NET_ON_COUNT=`echo "$NET_ON_LIST" | wc -l`
if (($NET_ON_COUNT != 1)); then
        echo "Need to set only one active ethernet connection."
        echo "This system currently has" $NET_ON_COUNT "connections in ON status"
        exit 1

rm -rf result.txt
echo "Checking started at " `date` | tee -a result.txt
echo "" | tee -a result.txt

trap 'echo "Checking ended at " `date` | tee -a result.txt' EXIT

NET_DEV=`echo $NET_ON_LIST | awk '{print $1}'`
RX_OK_PREV_COUNT=`ifconfig $NET_DEV | grep "RX packets" | awk '{ print $2}' | awk -F: '{print $2}'`
while [ 1 ]
        sleep 1.1
        RX_OK_COUNT=`ifconfig $NET_DEV | grep "RX packets" | awk '{ print $2}' | awk -F: '{print $2}'`
        if (($RX_OK_PREV_COUNT == $RX_OK_COUNT)); then
                echo "Value not changed for a second with value " $RX_OK_PREV_COUNT | tee -a result.txt
                echo "    at time " `date` | tee -a result.txt
                ifconfig $NET_DEV | tee -a result.txt

And a script for ping command.


[ -z $PING_SITE ] && PING_SITE=""

rm -rf send_data.txt
ping $PING_SITE | awk '/^[0-9]+ bytes from / { "date" | getline d; close("date -R") ; print d, ": ", $0; }'

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

A software engineer who loves any technologies that makes life easier. That’s why I love Linux and Mac at the same time.


%d bloggers like this: