[WBEL-users] simple bash script

Tanel Kindsigo tanel@kivilinn.tartu.ee
Tue, 7 Dec 2004 12:52:11 +0200 (EET)


well, you seem to have http server and want to limit its bandwidth?

first:
iptables -A OUTPUT -s yourip -p tcp --sport 80 -d ! 192.168.1.0/24 -p (if 
it's your LAN and you have only 1 NIC)
or
iptables -A OUTPUT -o eth0 -p tcp --sport 80 (if eth0 is your outgoing 
NIC)

then script something like that:
#!/bin/sh
while true
do
bytes = `iptables -L OUTPUT -n -v | grep (matching pattern) | awk (matching column)`
if [$bytes -ge 30000000000]
do
/etc/init-d/httpd stop
done
fi
sleep 600
done

use BASH programming howto to finish the script.




On Tue, 7 Dec 2004, Plug n Play wrote:

> Dear All,
> 
> First of all I’m not a script Enthusiast but wanted to automate something
> simple and need some of your programming expertise.
> 
> I'm planning to write a simple bash script to get the bandwidth consumption
> using ifconfig.
> 
> This is to avoid over usage of bandwidth with my hosting provider by setting
> my bandwidth limit
> (e.g. 30 gig). If I reach this 30 gig usage it will automatically trigger
> the httpd to stop to stop
> further transaction which can increase my bandwidth usage.
>