On 10-Jul-2001 Darcy Brodie wrote:
> Gregor Maier wrote:
> 
>
>> >
>> in addition to this job you could also run this script as cronjob which will
>> check if the connection (ppp0 interface) is still up. if not it will
>> reconnect
>> and it will also write to a logfile that the connection was down
>> I've written this script for a SuSE installation, so maybe you have to
>> change
>> some directories...
>>
>> #!/bin/bash
>> #
>> # This script checks if the specified (network-) interface is up by
>> # examining ifconfigs output. If the connection is down a new
>> # connection will be established
>> #
>>
>> # check this interface
>> IFACE=ppp0
>> # the pid-file of the iface
>> PIDFILE=/var/run/$IFACE.pid
>> LOGFILE=/var/log/adsl-status.log
>>
>> # We must be in RL 3 or 5, otherwise the script does nothing
>> if [  $(runlevel | awk '{ print $2 }') -gt 2 ]
>> then
>>     if ! /sbin/ifconfig | /usr/bin/grep --silent $IFACE
>>     then
>>         datestr=$(date +"%Y-%m-%d %H:%M:%S")
>>         echo $datestr Interface $IFACE is not up. Reconnecting. >> $LOGFILE
>>         /sbin/init.d/adsl stop >> $LOGFILE
>>         while [ -e $PIDFILE ]
>>         do
>>             sleep 1
>>         done
>>         sleep 2
>>         /sbin/init.d/adsl start >> $LOGFILE
>>         echo "---" >> $LOGFILE
>>     fi
>> fi
>> # END OF FILE
>>
>> /sbin/init.d/adsl is the script that does the work for
>> connecting/unconnecting.
>> On a normal linux installation (everything but SuSE) the directory is
>> /etc/init.d
>>
>> since my ISP uses PPTP and not PPoE for the adsl connection I got some
>> problems
>> when the connection died. (pppd stays alife,....). Therefor I shut down the
>> connection with adsl stop (which will kill the pppd), wait until pppd has
>> terminated and then i reconnect.
>>
>> Probalby you can just bring up your connection without the need to stop and
>> then start the connection.
>> So that you can do this:
>>
>> ...
>>  if ! /sbin/ifconfig | /usr/bin/grep --silent $IFACE
>>     then
>>         datestr=$(date +"%Y-%m-%d %H:%M:%S")
>>         echo $datestr Interface $IFACE is not up. Reconnecting. >> $LOGFILE
>>         COMMAND TO BRING CONNECTION UP
>>         echo "---" >> $LOGFILE
>>     fi
>>
> 
> Would I be correct in thinking that this script could be modified to also be
> able
> to monitor, and renew connection via a cable connection, by changing the
> IFACE to
> eth0, adn the commands to stop the connection, adn restart to ifdown eth0 and
> ifup
> eth0 ?  I have had trouble lately with my isp dropping my connection at work,
> and
> nobody can get any of their mail until I get in.
> 
> Darcy
> 
This would only work when your eth0 interface is down after you were
disconnected by your ISP and I don't think so. Run ifconfig after your
connection died and see if you still got the eth0 interface then. If so the
script won't work.
Or maybe you can still use the script with ppp0 device. My adsl connection is
like this. eth0 is connected to my adsl modem and when i bring up the
connection a ppp-tunnel will be created. This means the ppp0 interface is
brought but (again look at ifconfig this time when the connection is up). This
ppp0 interface is my link to the isp. All communication is encapsulated througt
the eth0 interface. Maybe your cable modem works like this.

If not you could use ping to verify your connection the problem is that if you
send 10 packages with ping and just one is lost ping will return a no zero exit
value. So maybe you're reconnection more often than necesarry but i should work
if test your connection like this

Ping must fail 2 times before we believe the connection is down. The reason
is, that when you send 5 ping packages and one gets lost, than there will be a
non zero exit value and the script would reconnect. If we do the ping twice it'
a little better.
 
if ! (ping -c 5 nameserver.yourproiver.com ||
      ping -c 5 nameserver.yourproiver.com )
then
   # connection is - bring it up again
   # do some logging
fi
  

gregor 
----------------------------------
E-Mail: Gregor Maier <[EMAIL PROTECTED]>
Date: 10-Jul-2001
Time: 09:03:11
----------------------------------

Reply via email to