From owner-freebsd-questions@FreeBSD.ORG Sat Sep 27 10:41:13 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 78DB216A4B3 for ; Sat, 27 Sep 2003 10:41:13 -0700 (PDT) Received: from www.bluecirclesoft.com (cpe-024-165-114-048.cinci.rr.com [24.165.114.48]) by mx1.FreeBSD.org (Postfix) with ESMTP id 639B143FE1 for ; Sat, 27 Sep 2003 10:41:12 -0700 (PDT) (envelope-from marc.ramirez@bluecirclesoft.com) Received: from www.bluecirclesoft.com (localhost [127.0.0.1]) h8RHfAN5000356; Sat, 27 Sep 2003 13:41:11 -0400 (EDT) (envelope-from mrami@bluecirclesoft.com) Received: (from mrami@localhost) by www.bluecirclesoft.com (8.12.9p1/8.12.9/Submit) id h8RHfA36000355; Sat, 27 Sep 2003 13:41:10 -0400 (EDT) (envelope-from mrami) Date: Sat, 27 Sep 2003 13:41:09 -0400 From: Marc Ramirez To: Brett Glass Message-ID: <20030927174109.GA67893@www.bluecirclesoft.com> References: <4.3.2.7.2.20030927103435.02caf820@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4.3.2.7.2.20030927103435.02caf820@localhost> User-Agent: Mutt/1.4.1i cc: questions@freebsd.org Subject: Re: Best way to modify /etc/ppp/ppp.secrets on the fly? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Sep 2003 17:41:13 -0000 On Sat, Sep 27, 2003 at 10:36:59AM -0600, Brett Glass wrote: > I need to write a program or script that modifies > /etc/ppp/ppp.secrets on the fly to add, change, and remove > passwords. One thing I do NOT want is for replacement of the file to > interfere with a login that's occurring at the same time. What's the > best way to slip a new version of the file in without messing up an > instance of userland PPP that might check it at just the wrong > moment? This is the way I do things like this; note that this does not do any locking on the file (man 1 lockf). #!/bin/sh -e REALNAME=/etc/ppp/secrets TEMPNAME=/etc/ppp/secrets.$$ trap "echo Error occurred 1>&2; rm -f $TEMPNAME" EXIT INT cp $REALNAME $TEMPNAME # do your stuff to $TEMPNAME trap "" INT # don't interrupt the FS ops unlink $REALNAME ln $TEMPNAME $REALNAME unlink $TEMPNAME trap EXIT INT -- Marc Ramirez Blue Circle Software Corporation 513-688-1070 (main) 513-382-1270 (direct) http://www.bluecirclesoft.com http://www.mrami.com (personal)