#!/bin/bash
# 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

