EN JA
SYSRC(8)
SYSRC(8) FreeBSD System Manager's Manual SYSRC(8)

NAME

sysrcsafely edit system rc files

SYNOPSIS

sysrc [ -cdDeFhinNqvx][ -f file][ -j jail | -R dir] name[ = value] ...

sysrc [ -cdDeFhinNqvx][ -f file][ -j jail | -R dir] -a | -A

DESCRIPTION

The sysrc utility retrieves rc.conf(5) variables from the collection of system rc files and allows processes with appropriate privilege to change values in a safe and effective manner.

The following options are available:

-a
Dump a list of all non-default configuration variables.
-A
Dump a list of all configuration variables (incl. defaults).
-c
Check only. For querying, return success if all requested variables are set (even if NULL), otherwise return error status. For assignments, return success if no changes are required, otherwise failure. If verbose (see “ -v”) prints a message stating whether variables are set and/or changes are required.
-d
Print a description of the given variable.
-D
Show default value(s) only (this is the same as setting RC_CONFS to NULL or passing `-f' with a NULL file-argument).
-e
Print query results as sh(1) compatible syntax (for example, ‘ var=value’). Ignored if either ‘ -n’ or ‘ -F’ is specified.
-f file
Operate on the specified file(s) instead of the files obtained by reading the ‘rc_conf_files’ entry in the RC_DEFAULTS file. This option can be specified multiple times for additional files.
-F
Show only the last rc.conf(5) file each directive is in.
-h
Print a short usage message to stderr and exit.
--help
Print a full usage statement to stderr and exit.
-i
Ignore unknown variables.
-j jail
The jid or name of the jail to operate within (overrides ‘ -R dir’; requires jexec(8)).
-n
Show only variable values, not their names.
-N
Show only variable names, not their values.
-q
Quiet. Disable verbose and hide certain errors.
-R dir
Operate within the root directory ‘ dir’ rather than ‘/’.
-v
Verbose. Print the pathname of the specific rc.conf(5) file where the directive was found.
--version
Print version information to stdout and exit.
-x
Remove variable(s) from specified file(s).

This utility has a similar syntax to sysctl(8). It shares the `-e' and `-n' options (detailed above) and also has the same ‘ name[=value]’ syntax for making queries/assignments.

However, while sysctl(8) serves to query/modify MIBs in the entrant kernel, sysrc instead works on values in the system rc.conf(5) configuration files.

The list of system configuration files is configured in the file ‘ /etc/defaults/rc.conf’ within the variable ‘ rc_conf_files’, which by-default contains a space-separated list of pathnames. On all FreeBSD systems, this defaults to the value "/etc/rc.conf /etc/rc.conf.local". Each pathname is sourced in-order upon startup. It is in the same fashion that sysrc sources the configuration files before returning the value of the given variable.

When supplied a variable name, sysrc will return the value of the variable. If the variable does not appear in any of the configured ‘ rc_conf_files’, an error is printed and error status is returned.

When changing values of a given variable, it does not matter if the variable appears in any of the ‘ rc_conf_files’ or not. If the variable does not appear in any of the files, it is appended to the end of the first pathname in the ‘ rc_conf_files’ variable. Otherwise, sysrc will replace only the last-occurrence in the last-file found to contain the variable. This gets the value to take effect next boot without heavily modifying these integral files (yet taking care not to allow the file to grow unwieldy should sysrc be called repeatedly).

ENVIRONMENT

The following environment variables are referenced by sysrc:
RC_CONFS
Override default ‘ rc_conf_files’ (even if set to NULL).
RC_DEFAULTS
Location of ‘ /etc/defaults/rc.conf’ file.

DEPENDENCIES

The following standard commands are required by sysrc:

awk(1), cat(1), chmod(1), env(1), grep(1), jls(1), mktemp(1), mv(1), rm(1), sh(1), stat(1), tail(1), chown(8) and jexec(8).

FILES

/etc/defaults/rc.conf
/etc/rc.conf
/etc/rc.conf.local

EXAMPLES

Below are some simple examples of how sysrc can be used to query certain values from the rc.conf(5) collection of system configuration files:

sysrc sshd_enable

returns the value of $sshd_enable, usually YES or NO.

sysrc defaultrouter

returns IP address of default router (if configured).

Working on other files, such as crontab(5):

sysrc -f /etc/crontab MAILTO

returns the value of the MAILTO setting (if configured).

In addition to the above syntax, sysrc also supports inline sh(1) PARAMETER expansion for changing the way values are reported, shown below:

sysrc 'hostname%%.*'

returns $hostname up to (but not including) first `.'.

sysrc 'network_interfaces%%[$IFS]*'

returns first word of $network_interfaces.

sysrc 'ntpdate_flags##*[$IFS]'

returns last word of $ntpdate_flags (time server address).

sysrc usbd_flags-"default"

returns $usbd_flags or default if unset or NULL.

sysrc cloned_interfaces+"alternate"

returns alternate if $cloned_interfaces is set.

sysrc '#kern_securelevel'

returns length in characters of $kern_securelevel.

sysrc 'hostname?'

returns NULL and error status 2 if $hostname is unset (or if set, returns the value of $hostname with no error status).

sysrc 'hostname:?'

returns NULL and error status 2 if $hostname is unset or NULL (or if set and non-NULL, returns value without error status).

LIMITATIONS

The sysrc utility presently does not support the ‘ rc.conf.d’ collection of system configuration files (which requires a service name to be known during execution).

This will be corrected by a future enhancement.

HISTORY

A sysrc utility first appeared in FreeBSD 9.2.

AUTHORS

Devin Teske <dteske@FreeBSD.org>

THANKS TO

Brandon Gooch, Garrett Cooper, Julian Elischer, Pawel Jakub Dawidek, Cyrille Lefevre, Ross West, Stefan Esser, Marco Steinbach, Jilles Tjoelker, Allan Jude, and Lars Engels for suggestions, help, and testing.
July 18, 2014 FreeBSD