1*4508Sjohnz#!/usr/bin/perl 2*4508Sjohnz# 3*4508Sjohnz# CDDL HEADER START 4*4508Sjohnz# 5*4508Sjohnz# The contents of this file are subject to the terms of the 6*4508Sjohnz# Common Development and Distribution License (the "License"). 7*4508Sjohnz# You may not use this file except in compliance with the License. 8*4508Sjohnz# 9*4508Sjohnz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*4508Sjohnz# or http://www.opensolaris.org/os/licensing. 11*4508Sjohnz# See the License for the specific language governing permissions 12*4508Sjohnz# and limitations under the License. 13*4508Sjohnz# 14*4508Sjohnz# When distributing Covered Code, include this CDDL HEADER in each 15*4508Sjohnz# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*4508Sjohnz# If applicable, add the following below this CDDL HEADER, with the 17*4508Sjohnz# fields enclosed by brackets "[]" replaced with your own identifying 18*4508Sjohnz# information: Portions Copyright [yyyy] [name of copyright owner] 19*4508Sjohnz# 20*4508Sjohnz# CDDL HEADER END 21*4508Sjohnz 22*4508Sjohnz# 23*4508Sjohnz# ident "%Z%%M% %I% %E% SMI" 24*4508Sjohnz# 25*4508Sjohnz# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 26*4508Sjohnz# Use is subject to license terms. 27*4508Sjohnz# 28*4508Sjohnz 29*4508Sjohnz# 30*4508Sjohnz# listsvcs [-e] profile ... 31*4508Sjohnz# 32*4508Sjohnz# List all service instances in an SMF profile. 33*4508Sjohnz# Options: 34*4508Sjohnz# -e List enabled instances only 35*4508Sjohnz# 36*4508Sjohnz 37*4508Sjohnzuse XML::Parser; 38*4508Sjohnzuse Getopt::Std; 39*4508Sjohnzuse strict; 40*4508Sjohnz 41*4508Sjohnzmy %opts; 42*4508Sjohnzmy $servicename; # name attribute of the enclosing service element 43*4508Sjohnzmy @svcs = (); # services list under construction 44*4508Sjohnz 45*4508Sjohnzif (!getopts("e", \%opts)) { 46*4508Sjohnz die "Usage: $0 [-e] profile ...\n"; 47*4508Sjohnz} 48*4508Sjohnzmy $list_all = !$opts{e}; 49*4508Sjohnz 50*4508Sjohnzmy $parser = new XML::Parser; 51*4508Sjohnz$parser->setHandlers(Start => \&start_handler, End => \&end_handler); 52*4508Sjohnz 53*4508Sjohnzfor my $file (@ARGV) { 54*4508Sjohnz $parser->parsefile($file); 55*4508Sjohnz} 56*4508Sjohnzprint join("\n", sort(@svcs)), "\n"; 57*4508Sjohnz 58*4508Sjohnzsub start_handler 59*4508Sjohnz{ 60*4508Sjohnz my ($p, $el, %attrs) = @_; 61*4508Sjohnz my $name; 62*4508Sjohnz 63*4508Sjohnz return unless ($attrs{"name"}); 64*4508Sjohnz $name = $attrs{"name"}; 65*4508Sjohnz 66*4508Sjohnz if ($el eq "service") { 67*4508Sjohnz $servicename = $name; 68*4508Sjohnz } elsif ($el eq "instance" && defined $servicename) { 69*4508Sjohnz push(@svcs, "$servicename:$name") 70*4508Sjohnz if ($list_all || $attrs{"enabled"} eq "true"); 71*4508Sjohnz } 72*4508Sjohnz} 73*4508Sjohnz 74*4508Sjohnzsub end_handler 75*4508Sjohnz{ 76*4508Sjohnz my ($p, $el) = @_; 77*4508Sjohnz 78*4508Sjohnz if ($el eq "service") { 79*4508Sjohnz $servicename = undef; 80*4508Sjohnz } 81*4508Sjohnz} 82