#!/bin/ksh
#set -x
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# R U N I N V E N T O R Y
#
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - -
# FileName : runinventories.ksh
# Author : ACOS
# Date : 24/07/02
# Subject : Run all inventory profiles
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - -
# Copyright(c) IBM 2005 PROVISO 4.4
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
THISFILE=`whence ${0}`
DIRNAME=`dirname ${THISFILE}`
PVMHOME="/opt/quallaby/datamart"
ARGS="$@"
PROGNAME="${0##*/}"
PROGNAME="${PROGNAME%%.*}"
LOGFILE="${DIRNAME}/${PROGNAME}.log"
: ${LOGMAXL:=10000}
: ${reloadFreq:=10}
#-------------------------------------------------------------------------------
# Default parameters
#-------------------------------------------------------------------------------
ACTION="all"
SEP="|"
let YES=0
let VERBOSE=0
#-------------------------------------------------------------------------------
# Command line keywords
#-------------------------------------------------------------------------------
KEY_ACTION="-action"
KEY_PROFILE="-profile"
KEY_SEP="-sep"
KEY_VERBOSE="-v"; # Verbose mode
KEY_YES="-Yes"; # Answer Yes to all questions
KEY_HELP="-?";
#
-----------------------------------------------------------------------------
# function Confirm
#
-----------------------------------------------------------------------------
function Confirm
{
if (( ! ${YES} ))
then
read IN?"${1}"
if [[ $IN == @(y|Y) ]]
then
return 0
else
return -1
fi
else
return 0
fi
}
#
-----------------------------------------------------------------------------
# function PrintError
#
-----------------------------------------------------------------------------
function PrintError
{
echo "`date \"+%m/%d/%Y-%H:%M:%S\"` [${PROGNAME}] Error : ${1}"
}
#
-----------------------------------------------------------------------------
# function PrintWarning
#
-----------------------------------------------------------------------------
function PrintWarning
{
echo "`date \"+%m/%d/%Y-%H:%M:%S\"` [${PROGNAME}] Warning : ${1}"
}
#
-----------------------------------------------------------------------------
# function PrintInfo
#
-----------------------------------------------------------------------------
function PrintInfo
{
echo "`date \"+%m/%d/%Y-%H:%M:%S\"` [${PROGNAME}] Info : ${1}"
}
#
-----------------------------------------------------------------------------
# function PrintLog
#
-----------------------------------------------------------------------------
function PrintLog
{
if (( ${VERBOSE} ))
then
echo "`date \"+%m/%d/%Y-%H:%M:%S\"` [${PROGNAME}] ${1}"
fi
}
#-------------------------------------------------------------------------------
# function PrintUsage
#-------------------------------------------------------------------------------
function PrintUsage
{
cat << USAGE
Usage : ${0##*/} [Options]
Where Options are
${KEY_ACTION} : Defines which modules to run
[discovery|synchro|grouping|user]
(default all)
${KEY_PROFILE} : Profile name (by default all profiles except
"default")
${KEY_SEP} : Set the field separator (default is "${SEP}")
${KEY_VERBOSE} : Verbose mode
(disable by default)
${KEY_YES} : Answer Yes to all questions
(disable by default)
${KEY_HELP} : Gives this help
Run Profiles, populate properties and perform a report grouping.
USAGE
}
#-------------------------------------------------------------------------------
# Help
#-------------------------------------------------------------------------------
if [[ ${1} = "-?" || ${1} = "-help" ]]
then
PrintUsage
exit 0
fi
#-------------------------------------------------------------------------------
# Parsing parameters
#-------------------------------------------------------------------------------
while [[ -n ${1} ]]
do
case ${1} in
"${KEY_ACTION}")
shift
if [[ -n ${1} ]]
then
ACTION="${1}"
else
PrintError "Missing mandatory parameter !"
PrintUsage
exit 3
fi
;;
"${KEY_PROFILE}")
shift
if [[ -n ${1} ]]
then
PROFILE="${1}"
else
PrintError "Missing mandatory parameter !"
PrintUsage
exit 3
fi
;;
"${KEY_SEP}")
shift
if [[ -n ${1} ]]
then
SEP="${1}"
else
PrintError "Missing mandatory parameter !"
PrintUsage
exit 3
fi
;;
"${KEY_VERBOSE}")
let VERBOSE=1
;;
"${KEY_YES}")
let YES=1
;;
* )
PrintError "Failed to parse arguments, unknown option:
\"${1}\"."
PrintUsage
exit 3
;;
esac
shift
done
#-------------------------------------------------------------------------------
# run env
#-------------------------------------------------------------------------------
. $PVMHOME/dataMart.env
#-------------------------------------------------------------------------------
# Retreive profiles list
#-------------------------------------------------------------------------------
if [ -z "${PROFILE}" ]
then
resmgr -export ogp -colNames "npath" | grep -v '#' | \
nawk -F "|" \
'{
n=split($1, TAB, "~")
if (n > 1)
{
PROFILE=TAB[2]
if ( (PROFILE != "") && (PROFILE != "default")
&& (index(PROFILE,"inv_")>0))
print PROFILE
}
}' | sort | uniq > ${PROGNAME}.profiles
else
echo ${PROFILE} > ${PROGNAME}.profiles
fi
#-------------------------------------------------------------------------------
# Running inventory for each profiles
#-------------------------------------------------------------------------------
typeset -i NBPROFILES=$(wc -l < ${PROGNAME}.profiles
2>/dev/null)
typeset -i profCnt=1
cat ${PROGNAME}.profiles |&
while read -p i
do
PrintLog "Launching inventory profile \"${i}\"..."
LOGFILE="${DIRNAME}/${PROGNAME}_${i}.log"
if ( (( profCnt % reloadFreq == 0 )) || (( profCnt ==
NBPROFILES )) )
then
inventory -noX -name "${i}" -action "${ACTION}" -reload 1
>> "${LOGFILE}" 2>&1
else
inventory -noX -name "${i}" -action "${ACTION}" >>
"${LOGFILE}" 2>&1
fi
if [ ${?} -ne 0 ]
then
PrintError "Inventory failed for profile \"${i}\"."
fi
sleep 60
profCnt=$((profCnt+1))
done
#-------------------------------------------------------------------------------
# Report autogrouping
#-------------------------------------------------------------------------------
PrintLog "running reportGrouping ...."
inventory -noX -reportGrouping >> "${LOGFILE}" 2>&1
#-------------------------------------------------------------------------------
# Cleaning temporary files
#-------------------------------------------------------------------------------
#rm -rf "${PROGNAME}.profiles" >/dev/null 2>&1
exit 0
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# E N D O F F I L E
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=