[wplug] Some scripting help (smoothwall)

Alexandros Papadopoulos apapadop at alumni.cmu.edu
Mon Feb 21 11:10:29 EST 2005


On Monday 21 February 2005 17:39, Mike wrote:
>  I've never really scripted anything before so I'm going to need all
>    the help I can get.  I run a smoothwall box for my internet
> firewall. Well lately my ISP's PPPOe server has been on the fritz
> requiring me to either reboot or renew my IP every so often to keep
> working. So I'm thinking, how about a script that I can put in cron
> to run every 5 mintues or so..
>    1.  ping XXX.XXX.XXX.XXX
>    a.  if response okay, do nothing.
>    b.  if response fails run:
>    /etc/rc.d/rc.netaddress.down; /etc/rc.d/rc.netaddress.up;
>    /usr/local/bin/restartsquid
>    and add log entry to some netrestart.log
>    Should be simple enough right, but where to begin..  :)

http://www.tldp.org/LDP/abs/html/testconstructs.html

The script you're looking for could look somewhat like this:

#!/bin/bash
# If we're online, don't renew our IP.
echo -n "Testing for connectivity: "
/bin/ping -c 2 XXX.XXX.XXX.XXX &> /dev/null
if [ $? -eq 0 ]
then
  # This means we're online
  echo -n "OK"
else
  echo -n " Not online, will renew our IP."
 /etc/rc.d/rc.netaddress.down
 sleep 1
/etc/rc.d/rc.netaddress.up
sleep 1
/usr/local/bin/restartsquid
echo "Renewed our IP at `date`" >> /var/log/netrestart.log
fi

This would obviously require running it as root, so test it well before 
use.

-A


More information about the wplug mailing list