[mdlug] efficient networking script?
Tony Bemus
tony at bemushosting.com
Wed Apr 6 12:35:16 EDT 2011
Hello all,
I just loaded an old laptop with a firewall distro called IP Fire
(http://www.ipfire.org/), it is based on IP Cop. I have set it up with
a green+red config. The red interface is a USB NIC(phone) and the green
is the built in NIC. When I unplug the USB NIC it looses the red
interface, as expected. then later I plug in the USB NIC and the red
interface is there but doesn't configure the static ip. If I run
"./etc/init.d/network restart" then the red interface get the static IP.
I wrote a script that checks if the interface is there and if there is
an IP address. If there is no interface it does nothing, if there is
an interface and a IP address it does nothing. but if there is an
interface and NO IP address then it restarts the network.
This allows my wife and I to just plug in the USB NIC (phone) and wait a
minute and then the Internet starts working, no commands to run.
My question: Is this an efficient way to do this?
I have fcron running the script every minuet.
#!/bin/bash
red=`ifconfig | grep red0 | wc -l`
if [ "${red}" -gt "0" ]; then
echo "Red Interface Exists";
ip=`ifconfig | grep 192.168.1.2 | wc -l`
if [ "${ip}" -gt "0" ]; then
echo "IP address Exists";
else
echo "Restarting network";
sh /etc/init.d/network restart
fi
else
echo "No Red Interface";
fi
Tony Bemus
More information about the mdlug
mailing list