#!/bin/sh - # # Copyright (C) 2005 by Oliver Fromme # All rights reserved. 2-clause BSD copyright/license and disclaimer applies. # # This is a wrapper for sysctl(8) with the following two # features: # # 1. "sysctl" without any arguments will behave as if the # -a option has been specified (similar to ifconfig(8)). # # 2. If only one argument is present that contains an # asterisk, it is interpreted as a wildcard pattern. # So, the following # sysctl kern.max* # is translated to: # sysctl -a | grep '^kern\.max.*:' # The exit value is 0 if any matching sysctl variables # were found and displayed, otherwise (no matches) the # exit code is 1. # # In all other cases the wrapper behaves exactly like the # original sysctl(8). # # I suggest that you store this script as "sysctl.wrapper", # and then make an alias sysctl="noglob sysctl.wrapper". # if [ $# -eq 0 ]; then exec sysctl -a elif [ $# -eq 1 ]; then case "$1" in -*) ;; *"*"*) OID="$1" while [ -n "$OID" ]; do case "$OID" in *.*"*"*) OID="${OID%.*}" ;; *"*"*) OID="-a" ;; *) break ;; esac done PATTERN=$(echo "$1" | sed 's/\./\\./g;s/\*/.*/g') sysctl $OID | grep "^${PATTERN}:" exit $? ;; esac fi exec sysctl "$@" #--