#!/bin/sh
#
# ############################################################################
# Copyright (c) 2012-2023 Dell Inc. or its subsidiaries. All rights reserved.
# All trademarks used herein are the property of their respective owners.
#
# This script displays all the 'dead' paths known to PowerPath.
# ############################################################################
#

####
#   import platform specific check routines here if needed.
#   DO NOT REMOVE THE FOLLOWING LINE
####

NDU_LOCK_FILE=/etc/opt/emcpower/.ndu_lock

if [ -f ${NDU_LOCK_FILE} ]; then
    echo "Warning: PowerPath non disruptive upgrade is in progress."
    echo "Please retry after the upgrade is complete."
    exit 1
fi


powermt display dev=all | awk '
BEGIN {
    cnt = 0
    dead = 0
    tot_dead = 0
}
{
    if (NF > 0) {
        lines[cnt]  = $0
        cnt++
        if ($0 ~ /\ydead\y/ && $1 !~ /^state/) {
               dead++
               tot_dead++
        }
    }

    if (NF == 0) {
        if (dead > 0) {
            for ( x = 0; x < cnt; x++)
                print lines[x]
            print ""
        }
        cnt = 0
        dead = 0
   }
}
END {
    if (dead > 0) {
        for ( x = 0; x < cnt; x++)
            print lines[x]
        print ""
    }
    print "Total dead paths:", tot_dead
}'

