#!/pkg/bin/ksh::
################################################################################
# tech_fabric_common - show tech-support fabric comman library script
# Description:
# This script is the library that provides common functions for all fabric
# show tech-support feature.
#
# Jan 2010, Pratap Kandregula
#
# Copyright (c) 2006-2020 by cisco Systems, Inc.
# All rights reserved.
#
################################################################################
#

ext_node_name=`node_list_generation -f MY`
int_node_name=`node_conversion -N $ext_node_name`

exec_diagnif_per_port_cmd() {

    location=$ext_node_name
    pq_nodeid=`node_conversion -I $location`
    fq_nodeid=`node_conversion -i $int_node_name`
    inst=$1

    cmd_exec='show controllers fia diagshell $inst \"diag nif\" location $location'
    cmd__ksh='fia_driver_show -c \"diag nif norates\" -u $inst -n $fq_nodeid'
    cmd_exec=$(eval "echo $cmd_exec")
    if [ -z "$2" ]; then
         echo "+++ $cmd_exec [`iosclock -d 0`] ++++"
    else
        echo "+++ $cmd_exec [`iosclock -d 0`] ++++" >> "$2"
    fi
    cmd__ksh=$(eval "echo $cmd__ksh")
    echo $cmd__ksh
    cmd__output=$(eval $cmd__ksh)

    if [ -z "$2" ]; then
        echo ${cmd__output}
    else
        echo ${cmd__output} >> "$2"
    fi
#    bk_IFS=$IFS
#    IFS="\n"
#    readarray -t -s 6 arr <<<"$cmd__output"
#    val=0;
#    for line in ${arr[*]}; do
#        read -d '|' elem <<<"$line"
#        elem_cmd_output=$(eval "fia_driver_show -c \"diag nif port $elem\" -u $inst -n $fq_nodeid")
#        if [ $val == 0 ]; then
#            readarray -t -s 1 just_output <<<"$elem_cmd_output"
#
#            if [ -z "$2" ]; then
#                echo ${just_output[0]}
#                echo ${just_output[1]}
#                echo ${just_output[2]}
#                echo ${just_output[3]}
#                echo ${just_output[4]}
#                echo ${just_output[5]}
#            else
#                echo ${just_output[0]} >> "$2"
#                echo ${just_output[1]} >> "$2"
#                echo ${just_output[2]} >> "$2"
#                echo ${just_output[3]} >> "$2"
#                echo ${just_output[4]} >> "$2"
#                echo ${just_output[5]} >> "$2"
#            fi
#            val=1
#        else
#            readarray -t -s 6 just_output <<<"$elem_cmd_output"
#            if [ -z "$2" ]; then
#                echo ${just_output[0]}
#            else
#                echo ${just_output[0]} >> "$2"
#            fi
#        fi
#        line=${arr[$val]}
#    done
#    IFS=$bk_IFS
    if [ -z "$2" ]; then
        echo "--- $cmd_exec [`iosclock -d 0`] ----"
    else
        echo "--- $cmd_exec [`iosclock -d 0`] ----" >> "$2"
    fi
}

