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.
#!/bin/bash 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 fi 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 ] do 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 fi RX_OK_PREV_COUNT=$RX_OK_COUNT done
And a script for ping command.
#!/bin/bash PING_SITE=$1 [ -z $PING_SITE ] && PING_SITE="google.com" 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