LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash-scripting for iptables/munin (https://www.linuxquestions.org/questions/programming-9/bash-scripting-for-iptables-munin-760352/)

XCayenne 10-07-2009 12:12 PM

Bash-scripting for iptables/munin
 
Hi,
I am trying to write this munin script to log all the accepted TCP/UDP/ICMP packets that are comming trough my iptable firewall.I then need a bash-script that will collect the packets that are comming trough the firewall.

The IPtable output could briefly looks like this:
Quote:

Chain INPUT:
pktg bytes target prot
3 254 accept tcp
What I need is a script that fetches i.e. accepted tcp connections, where the packet state is 1<=. I need a way to "look" at the pktg-colum to determind if the value is at least 1.

This is what i got for now:
Quote:

#!/bin/bash

if [ "$1" = "config" ]; then

echo munin-graph info.......................
echo munin-graph info.......................
echo munin-graph info.......................


exit 0;
fi


echo -n "tcp.value ";iptables -vxL | grep tcp | grep ACCEPT | awk '{print $1}'
echo -n "udp.value ";iptables -vxL | grep udp | grep ACCEPT | awk '{print $1}'
echo -n "icmp.value ";iptables -vxL | grep icmp | grep ACCEPT | awk '{print $1}'
echo -n "total.value ";iptables -vxL | grep ACCEPT | awk '{print $1}'


carltm 10-09-2009 06:03 AM

Quote:

Originally Posted by XCayenne (Post 3711193)
What I need is a script that fetches i.e. accepted tcp connections, where the packet state is 1<=. I need a way to "look" at the pktg-colum to determind if the value is at least 1.

I'm not sure what you mean by "the packet state is 1<=."
It seems to me that you'd want to know the current value
whether it is 0 or not.

Incidentally, here is an easier/quicker way to get a line of output
for your script.

Quote:

echo tcp.value `iptables -vxL | grep 'ACCEPT.*tcp' | cut -c1-8`


All times are GMT -5. The time now is 07:17 AM.