6 # The contents of this file are subject to the terms of the
7 # Common Development and Distribution License (the "License").
8 # You may not use this file except in compliance with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
25 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 # Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
29 export PATH
=/usr
/xpg
6/bin
:/usr
/xpg
4/bin
:/bin
:/usr
/bin
31 # Make sure all math stuff runs in the "C" locale to avoid problems
32 # with alternative # radix point representations (e.g. ',' instead of
33 # '.' in de_DE.*-locales). This needs to be set _before_ any
34 # floating-point constants are defined in this script).
35 if [[ "${LC_ALL}" != "" ]] ; then
37 LC_MONETARY
="${LC_ALL}" \
38 LC_MESSAGES
="${LC_ALL}" \
39 LC_COLLATE
="${LC_ALL}" \
47 print
-u2 "${progname}: $*"
52 function svcproptovartree
66 while IFS
=' ' read -A fields
; do
67 num_fields
=${#fields[*]}
70 datatype
="${fields[1]}"
71 # parse service/property name
72 servicename
="${name%~(Er):properties/.*}"
73 servicename
="${servicename/~(El)svc:\//}" # strip "svc:/"
74 propname
="${name#~(El).*:properties/}"
76 [[ "${ typeset +p "tree[${servicename}].properties" ; }" == "" ]] && compound
-A tree
[${servicename}].properties
78 nameref node
=tree
[${servicename}].properties
[${propname}]
81 typeset datatype
="${datatype}"
82 typeset valuelist
="true"
86 for (( i
=2 ; i
< num_fields
; i
++ )) ; do
87 node.values
+=( "${fields[i]}" )
97 getopts -a "${progname}" "${svcproptree1_usage}" OPT
'-?'
107 typeset progname
="${ basename "${0}" ; }"
109 typeset
-r svcproptree1_usage
=$
'+
110 [-?\n@(#)\$Id: svcproptree1 (Roland Mainz) 2010-04-02 \$\n]
111 [-author?Roland Mainz <roland.mainz@nrubsig.org>]
112 [+NAME?svcproptree1 - SMF tree demo]
113 [+DESCRIPTION?\bsvcproptree1\b is a small ksh93 compound variable demo
114 which reads accepts a SMF service pattern name input file,
115 reads the matching service properties and converts them into an internal
116 variable tree representation and outputs it in the format
117 specified by viewmode (either "list", "namelist", "tree" or "compacttree")..]
121 [+SEE ALSO?\bksh93\b(1), \bsvcprop\b(1)]
124 while getopts -a "${progname}" "${svcproptree1_usage}" OPT
; do
125 # printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
132 typeset svcpattern
="$1"
133 typeset viewmode
="$2"
135 if [[ "${viewmode}" != ~
(Elr
)(list|namelist|tree|compacttree
) ]] ; then
136 fatal_error $
"Invalid view mode \"${viewmode}\"."
145 s
="$(/usr/bin/svcprop -f "${svcpattern}")" || fatal_error $
"svcprop failed with exit code $?."
146 print
-u2 $
"#loading completed."
148 print
-r -- "$s" | svcproptovartree svc.proptree
149 print
-u2 $
"#parsing completed."
151 case "${viewmode}" in
153 set |
egrep "^svc.proptree\[" | fgrep
-v ']=$'
156 typeset
+ |
egrep "^svc.proptree\["
165 fatal_error $
"Invalid view mode \"${viewmode}\"."