Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Using the sysctl() Extension Function on Junos Devices

Junos OS and Junos OS Evolved run on *nix-like operating systems, which enable you to retrieve various kernel state and process information. You can invoke the sysctl() extension function in your automation scripts to retrieve this same kernel state information, similar to how you would use the sysctl command in the shell to retrieve these values. The sysctl() function takes the same variable names that you would provide for the sysctl command in the shell. The variable name is a MIB-style name, which uses a dotted set of components. Because Junos OS is based on FreeBSD and Junos OS Evolved runs natively on Linux, the sysctl variables and variable names are different for each OS.

Note:

You can execute the sysctl -a command in the shell to see the entire list of available states and the corresponding names that you can provide as arguments to the sysctl() function. However, the output can be extensive.

For example, on Junos OS, the following sample SLAX op script retrieves and prints the values for the sysctl states kern.hostname and hw.product.model:

Similarly, on Junos OS Evolved, the following sample SLAX op script retrieves and prints the values for the sysctl states kernel.hostname and kernel.osrelease:

Note:

For Junos OS Evolved, the return type is always a string ("s"). If you omit the type argument, the default is "s".

Junos OS and Junos OS Evolved have different sysctl state names because the underlying operating systems are different. For example, in Junos OS, you can retrieve the kernel state for hw.product.model, but Junos OS Evolved does not have a similar sysctl variable name. In those cases, you can use RPCs or other means to retrieve the same information.

For example, the following SLAX op script executes the get-software-information RPC to retrieve the model name on Junos OS Evolved, which is equivalent to returning the sysctl hw.product.model value on Junos OS.

If you invoke the sysctl() function in a script and specify a nonexistent sysctl variable name, Junos OS does not generate an error, but Junos OS Evolved generates a sysctl error: No such file or directory error.

For example, suppose the sysctl() function requests the value for hw.product.model, which is a valid sysctl variable name on Junos OS but is not a valid sysctl variable name on Junos OS Evolved. If you execute the script on a device running Junos OS Evolved, the script emits the following output: