#!/bin/bash
#
# Copyright (c) International Business Machines  Corp., 2001
#
# This program is free software;  you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY;  without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
# the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program;  if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Simple shell script to collect EVMS information.

# This is the subroutine that collects data through the evms command line
# interface. The only parm it expects is the full path to the evms command.
execute_cli () {
   evms_cli=$1
   
   echo "############################################################"
   echo "                  Data from the EVMS Engine"
   echo "############################################################"
   echo
   echo

   # Create the command file to be processed by the EVMS CLI
   echo "/* EVMS Command File to gather info about a system for debugging. */" \
                                                     > evms_gather_info.tmp.$$
   echo "q:p       /* List all engine plug-ins. */" >> evms_gather_info.tmp.$$
   echo ":q:D,lo   /* List all disks.           */" >> evms_gather_info.tmp.$$
   echo ":q:S,lo   /* List all segments.        */" >> evms_gather_info.tmp.$$
   echo ":q:C,lo   /* List all containers       */" >> evms_gather_info.tmp.$$
   echo ":q:R,lo   /* List all regions          */" >> evms_gather_info.tmp.$$
   echo ":q:O,U,lo /* List all feature objects  */" >> evms_gather_info.tmp.$$
   echo ":q:V,lo   /* List all volumes          */" >> evms_gather_info.tmp.$$

   # Run this command file.
   $evms_cli -f evms_gather_info.tmp.$$
   rm -f evms_gather_info.tmp.$$
}

evms_cli=`which evms 2>&1 | grep "no evms"`

if [ -z "$evms_cli" ]; then

   evms_cli=`which evms`
   execute_cli $evms_cli

else

   evms_cli=`whereis -b evms | awk '{print $2}'`
   
   if [ $? -eq 0 -a -n "$evms_cli" ]; then
       execute_cli $evms_cli
   else
       echo "############################################################"
       echo "                   EVMS CLI not found!"
       echo "                 Cannot get engine data!"
       echo "############################################################"
       echo
       echo
   fi
   
fi

