#!/usr/bin/perl
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2019,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/utilities/cl_cw_harvest_vg.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2001,2013 
# 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 
# @(#)  7d4c34b 43haes/usr/sbin/cluster/utilities/cl_cw_harvest_vg.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM 
# FILE:  cl_cw_harvest_vg
#
# NOTE:  This file is assumed to be called when harvesting is required
#        cluster-wide.
#
##########################################################

use lib '/usr/es/lib/perl/';  #Adds a directory to perl's library path
use libcl_untaint;

# =============================================================================
# Standard setup stuff here.
# ----------------------------
# Set the ENV PATH variable
$0 = untaint($0);
$dirname = untaint(`/usr/bin/dirname/ $0`); chop($dirname);
$prog = untaint(`/usr/bin/basename $0`);    chop($prog);


# Set the ENV ODMDIR variable.
# ---------------------------
$HA_DIR = untaint(`cl_get_path`);

$odmdir = "/etc/$HA_DIR/objrepos";
$ENV{'ODMDIR'} = "$odmdir";

# =============================================================================
# Set write buffer to flush on a line-by-line basis.
$| = 1;
# =============================================================================

   # ---------------------------------
   # Build the @cluster_nodes array.
   # ----------------------------------
   $rawout = `clodmget -q object=COMMUNICATION_PATH -n -f name HACMPnode`;
		$ret_val = ( $? >> 8);
		if( $ret_val != 0 )    {
				$msg_str = "dspmsg -s 10 utilities.cat 10 \"$prog:  Error getting cluster nodes.\n\" $prog";
				system("$msg_str");
				exit 1 ;
		}
   # ---------------------------------------
		@cluster_nodes = split("\n", $rawout);
                for(@cluster_nodes){
                        $_ = untaint($_);
		} 
                 
		$cl_nodes = join(',', @cluster_nodes);
   # ---------------------------------------

		if ( ! @cluster_nodes ) {
				$msg_str = "dspmsg -s 10 utilities.cat 20 \"$prog:  No cluster nodes found.\n\" $prog";
				system("$msg_str");
				exit 1 ;
		} 		

# ---------------------------------------
# Now run dsh and generate the data file.
# ----------------------------------------

		$cl_getpv_output = `cl_getpv -cspoc \"-f -n $cl_nodes\"`;
                $cl_getpv_output = untaint($cl_getpv_output);
		$ret_val = ($? >> 8);

		if($ret_val != 0) 
		{
				# this is an error - like - wrong command , HA not installed
				$msg_str = "dspmsg -s 10 utilities.cat 50 \"$prog: Error gathering cluster information.\n\" $prog";
				system("$msg_str");
				exit 1 ;
		}

    # Redirect output.

    print  "$cl_getpv_output";

#------------END--------------
