Best way to modify /etc/ppp/ppp.secrets on the fly?

Marc Ramirez marc.ramirez at bluecirclesoft.com
Sat Sep 27 10:41:13 PDT 2003


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)


More information about the freebsd-questions mailing list