Date: Mon, 7 Jul 1997 15:13:56 -0700 (PDT) From: "Eric J. Schwertfeger" <ejs@bfd.com> To: Kenneth Ingham <ingham@i-pi.com> Cc: Nathan Dorfman <nathan@deimos.senate.org>, freebsd-questions@FreeBSD.ORG Subject: Re: pppd Auto-reconnect? Message-ID: <Pine.BSF.3.95.970707151059.10884A-100000@harlie.bfd.com> In-Reply-To: <199707072125.PAA17502@socrates.i-pi.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 7 Jul 1997, Kenneth Ingham wrote: > > Is it possible to have pppd reconnect automatically? I have a script > Here's how I do mine. I have a 24x7 dial-up PPP connection. > > In /etc/ttys: > > cuaa1 "/usr/sbin/pppd /dev/cuaa1 115200 -detach" unknown on insecure > > So whenever it dies, init re-spawns it. Works well. For some reason, that doesn't work for me, sometimes I loose the ppp connection, but pppd doesn't exit, so I came up with the following perl script that I use for /etc/ppp/ip-up #!/usr/bin/perl # pppmon.pl # a simple script to detect when pppd goes down. functions by watching the # incoming packetcounts returned by netstat, pinging when there's no traffic, # and killing ppd when the pings don't generate traffic. Works with perl4 or # perl 5 # read arguments $ifname=$ARGV[0]; $rmtaddr=$ARGV[4]; # initialize parameters # delay is the number of seconds between updates # limit is the number of times a 0 packet count is returned before killing # pppd $delay=10; $limit=2; #initialize other variables $zerocount=0; # get ppp pid for later kill open(INPUT,"/var/run/$ifname.pid"); $pid=int(<INPUT>); close(INPUT); sub ppplog { ($sec,$min,$hour,$mday,$mon,$year)=localtime(time); $logstr=sprintf("%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d ",$mon,$mday, $year%100,$hour,$min,$sec).$_[0]."\n"; open(LOG,'>>/var/log/pppmon'); print LOG $logstr; close(LOG); } # log starting &ppplog('pppmon started, device='.$ifname.' , process='.$pid.', remote address='.$rmtaddr); # open netstat open(DATA,"netstat -n -I $ifname -w $delay|"); while($line=<DATA>) { if(!kill(0,$pid)) { close(DATA); &ppplog('pppmon exiting, lost process '.$pid); exit; } if($line =~ /^[\s\d]+$/) { $newcount=(split(/\s+/,$line))[1]; if($newcount==0) { $zerocount++; if($zerocount>=$limit) { kill('HUP',$pid); close(DATA); &ppplog('pppmon exiting, killing process '.$pid); exit; } else { system('/sbin/ping -c 3 '.$rmtaddr.' >/dev/null 2>/dev/null &'); } } else { $zerocount=0; } } } close(DATA); &ppplog('pppmon exiting, lost netstat for device '.$ifname);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.970707151059.10884A-100000>