Date: Wed, 06 Oct 2010 13:53:26 -0700 From: Devin Teske <dteske@vicor.com> To: freebsd-hackers@freebsd.org Cc: Devin Teske <dteske@vicor.com> Subject: Re: sysconf -- a sysctl(8)-like utility for managing /etc/rc.conf et. al. Message-ID: <1286398406.27308.43.camel@localhost.localdomain> In-Reply-To: <1286397912.27308.40.camel@localhost.localdomain> References: <1286397912.27308.40.camel@localhost.localdomain>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-KH81D1WZUAaMnfmeqsg6 Content-Type: text/plain Content-Transfer-Encoding: 7bit Oops =) This version will use grep(1) if installed. Diff below. dteske@dt.vicor.com Desktop $ diff -pub sysconf.txt{.orig,} --- sysconf.txt.orig 2010-10-06 13:50:29.000000000 -0700 +++ sysconf.txt 2010-10-06 13:50:45.000000000 -0700 @@ -349,8 +349,7 @@ depend sysconf_set 'local' 'sysconf' '[' local found= local regex="^[[:space:]]*$varname=" for file in $conf_files; do - #if have grep; then - if false; then + if have grep; then grep -q "$regex" $file && found=1 else while read LINE; do \ @@ -386,8 +385,7 @@ depend sysconf_set 'local' 'sysconf' '[' ( found= while read -r LINE; do if [ ! "$found" ]; then - #if have grep; then - if false; then + if have grep; then match="$( echo "$LINE" | grep "$regex" )" else case "$LINE" in On Wed, 2010-10-06 at 13:45 -0700, Devin Teske wrote: > Hello fellow freebsd-hackers, > > Long-time hacker, first-time poster. > > I'd like to share a shell script that I wrote for FreeBSD system > administration. > > The attached shell script works similar to sysctl(8), but rather than > querying or working on sysctl MIBs, it instead works on the /etc/rc.conf > (and /etc/rc.conf.local) files. > > Syntax shown below (available by running the script without arguments): > > Usage: sysconf [OPTIONS] name[=value] ... > OPTIONS: > -h --help Print this message to stderr and exit. > -d Print list of internal dependencies before exit. > -e Print query results as `var=value' (useful for producing > output to be fed back in). Ignored if -n is specified. > -n Show only variable values, not their names. > > ENVIRONMENT: > SYSCONF_SHOW_DEPS Dump list of dependencies. Must be zero or one > (default: `0') > RC_DEFAULTS Location of `/etc/defaults/rc.conf' file. > > Examples: > > root@mymachine ~ $ sysconf hostname > hostname: mymachine.localdomain > root@mymachine ~ $ sysconf hostname=foomaster.deluxe.com > hostname: mymachine.localdomain -> foomaster.deluex.com > root@mymachine ~ $ sysconf -e hostname > hostname="foomaster.deluxe.com" > root@mymachine ~ $ sysconf -n hostname > foomaster.deluxe.com > > The script has zero external dependencies. None. Period. It will use > grep(1) if installed, but it is not required. > > Tested extensively on FreeBSD-4.8, FreeBSD-4.11, FreeBSD-8.0, and > FreeBSD-8.1. -- Cheers, Devin Teske -> CONTACT INFORMATION <- Business Solutions Consultant II FIS - fisglobal.com 510-735-5650 Mobile 510-621-2038 Office 510-621-2020 Office Fax 909-477-4578 Home/Fax devin.teske@fisglobal.com -> LEGAL DISCLAIMER <- This message contains confidential and proprietary information of the sender, and is intended only for the person(s) to whom it is addressed. Any use, distribution, copying or disclosure by any other person is strictly prohibited. If you have received this message in error, please notify the e-mail sender immediately, and delete the original message without making a copy. -> END TRANSMISSION <- --=-KH81D1WZUAaMnfmeqsg6--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1286398406.27308.43.camel>