From owner-freebsd-questions Mon Jul 7 15:14:22 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id PAA12293 for questions-outgoing; Mon, 7 Jul 1997 15:14:22 -0700 (PDT) Received: from horst.bfd.com (horst.bfd.com [204.160.242.10]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA12281 for ; Mon, 7 Jul 1997 15:14:13 -0700 (PDT) Received: from harlie.bfd.com (bastion.bfd.com [204.160.242.14]) by horst.bfd.com (8.8.5/8.7.3) with SMTP id PAA02072; Mon, 7 Jul 1997 15:13:56 -0700 (PDT) Date: Mon, 7 Jul 1997 15:13:56 -0700 (PDT) From: "Eric J. Schwertfeger" To: Kenneth Ingham cc: Nathan Dorfman , freebsd-questions@FreeBSD.ORG Subject: Re: pppd Auto-reconnect? In-Reply-To: <199707072125.PAA17502@socrates.i-pi.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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(); 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=) { 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);