LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Command to grep and the Drop Count for scripting (https://www.linuxquestions.org/questions/linux-general-1/command-to-grep-and-the-drop-count-for-scripting-4175464837/)

rajaniyer123 06-05-2013 09:59 AM

Command to grep and the Drop Count for scripting
 
Hi,

I would like to set up the script to monitor the Network interface level packet drops, in which I would like to set up the logic in such a way that when dropped:0 will increase above 100 it should send alert.

RX packets:237722797 errors:0 dropped:0 overruns:0 frame:0

Please let me know an idea how we can set the logic for this in bash script ?

Thanks
Rajan

rigor 06-06-2013 01:12 AM

rajaniyer123,

For the short term, depending on what you need, you might be able to do something, simple, and brute force such as this:

Code:

#!/bin/bash

dropped_count=`/sbin/ifconfig eth0 | fgrep 'RX packets' | cut -d: -f3-3 | cut -d' ' -f1`

while [[  1  -eq  1  ]]
    do
        if [[  $dropped_count  -gt  100  ]]
            then
            # Put actual ALERT logic here instead of the echo.
            echo ALERT
        fi

        sleep 60
    done

But long term, if I wanted to monitor dropped packets, especially if I thought I might need to do something more involved with it in the future, then for the sake of elegance, I might look into something like extending iptables, building a custom module, so I could launch whatever program I wished, when a threshold was exceeded.

Hope this helps.


All times are GMT -5. The time now is 05:05 PM.