On Saturday 15 May 2004 21:40, Noam Meltzer wrote:
> Hetz Ben Hamo wrote:
> > Hi,
> >
> > I have a situation which is well known to people - your machine is
> > connected (PPTP) to the net, but sometimes there's disconnection

> I have such scripts, which I managed to write during the time (and based
> on other scripts which I found on the internet.  - sorry, but i don't

FWIW, I also have a script to do the job. It's not as **smart** as what Noam 
suggested, but it works well for me (running as a cron job every 2 minutes). 
The basic idea is to check if the connection is up (not depending on ifconfig 
which may report a ppp connection even when pptp has died). The only 
**special** thing I did was a sort of primitive **limited time locking**. My 
problem was that sometimes the reconnection takes more than 2 minutes and 
this would result in more than 1 copy of the script running. On the other 
hand, a **normal** lock file wouldn't solve the problem if the computer 
itself locked up. Because when it restarted, the old, out-of-date lock file 
would still be there. So I test the lock file to see if it should be deleted. 
All the rest is self explanatory.

I'm including 3 scripts (and as with Noam's script, you also need a firewall 
script). I put in a phoney username in the last script (my paranoia).


>>>>>>>>>>>>  file 1 - myADSLtest  <<<<<<<<<<<<<<<

#!/bin/bash
## myADSLtest -  reset ADSL if it stops responding  - run every 2 minutes 

MYDATE=`(set \`date\`; echo $1 $2 $3 $4 $5 $6)`

## is the script already running?
if test -e /tmp/tst-lock-myADSLtest; then   ## lock exists so already running
   echo "myADSLtest is already running so let's quit  " $MYDATE  
>> /var/log/mylogs/adsl-down.log
   cat /tmp/tst-lock-myADSLtest
## next line adds an "X" to the lock file - for use in testing old lock files
   echo "X" >> /tmp/tst-lock-myADSLtest

## next lines delete lock file older than 20 minutes
   grep -c "X" /tmp/tst-lock-myADSLtest | grep 9 
> /tmp/tst-for-old-lock-myADSLtest

 if test -s /tmp/tst-for-old-lock-myADSLtest; then 
## not a zero sized file so 9 Xs (i.e. 20 minutes) found
    echo "we should remove the old lock file"
    rm -f /tmp/tst-lock-myADSLtest  
 else
    echo "the file isn't old enough to remove"
 fi
   exit
fi

## create the lock file
touch /tmp/tst-lock-myADSLtest

## fping instead of ping - allows testing more than one address
fping www.barak-online.net www.google.co.il www.google.com | grep "is alive" 
> /tmp/tst-if-alive
if test -s /tmp/tst-if-alive; then   ## not a zero file - found "is alive" 
  echo "ping is OK - we're online"                       
else
  echo "<<< not OK  >>>"              >> /var/log/mylogs/adsl-connect.log
  echo "calling myadslreset "         >> /var/log/mylogs/adsl-connect.log
  echo "ADSL was down at: " $MYDATE >> /var/log/mylogs/adsl-down.log
   /data1/myscripts/myadslreset     >> /var/log/mylogs/adsl-connect.log
  MYDATE=`(set \`date\`; echo $1 $2 $3 $4 $5 $6)`
  echo "ADSL back up at ---- " $MYDATE >> /var/log/mylogs/adsl-connect.log
  echo "ADSL back up at ---- " $MYDATE >> /var/log/mylogs/adsl-down.log
fi

## delete the lock file
rm -f /tmp/tst-lock-myADSLtest



>>>>>>>>>>>>  file 2 - myadslreset  <<<<<<<<<<<<<<<

#!/bin/bash
## reset ADSL if it stops responding
killall pptp
killall pppd
echo "clearing unix domain - ADSL   - suggested by mulix 20/2/01"
rm -f /var/run/pptp/10.0.0.138

## sleep a bit to make sure the previous steps finished
sleep 10

/data1/myscripts/myintermail
/data1/myscripts/myFWup


>>>>>>>>>>>>  file 3 - myintermail  <<<<<<<<<<<<<<<

#!/bin/bash
## start ADSL on InterMail 

ifconfig eth0 10.200.1.1 netmask 255.0.0.0 mtu 1500

## next line changed for InterMail 28-3-04   1-800-206-207
##    - also note changes to pap-secrets and chap-secrets
pptp   10.0.0.138 debug user [EMAIL PROTECTED] remotename "10.0.0.138 
RELAY_PPP1" defaultroute netmask 255.0.0.0 mtu 1452 noauth
 


-- 
Shlomo Solomon
http://come.to/shlomo.solomon
Sent by KMail 1.6.1 (KDE 3.2) on LINUX Mandrake 10.0


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to