#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/ksh93/aix/odm/KLIB_AIX_ODM_get_odm_fields.sh 1.4 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2005,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)71 1.4 src/43haes/lib/ksh93/aix/odm/KLIB_AIX_ODM_get_odm_fields.sh, hacmp, 61haes_r714 11/28/11 15:14:41 # #=head1 NAME # # KLIB_AIX_ODM_get_odm_fields - Print value of qualified ODM fields # #=head1 SYNOPSIS # # ip_label=$(KLIB_AIX_ODM_get_odm_fields "name=SERVICE_LABEL and group=rg1" "HACMPresource" "value") # if (( $? == 0 )); then # echo $ip_label # fi # #=head1 DESCRIPTION # # Prints the values of any field in a stanza that matches the supplied query string. # #=head1 ARGUMENTS # # arg1 - predicate literal scalar, string to pass to odmget -q predicate # arg2 - literal odm class name # arg3... literals field names extract # #=head1 RETURN # # 0 - success, found the fields from the class # 1 - failed, unable to find the class, or invalid predicate # #=head1 COPYRIGHT # #(C) COPYRIGHT International Business Machines Corp. 2005 #All Rights Reserved # #=cut # function KLIB_AIX_ODM_get_odm_fields { . /usr/es/lib/ksh93/func_include typeset -i result=0 odmget -q "$1" "$2" 2>/dev/null | { shift 2 typeset field eq rest arg while read field eq rest; do [[ -z ${rest} || " $* " != *\ $field\ * ]] && continue eval echo $rest # eval strips extra quotes (( ++result )) done } (( result )) }