#!/bin/sh
#
# ############################################################################
# Copyright (c) 2012-2014, EMC Corporation.  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
#
# Routines to check root authorization and if PowerPath is active on Linux
#

#
# Check root authorization
#
ruid=`id -ru`
euid=`id -u`
if [ $ruid -ne 0 -o $euid -ne 0 ]; then
    echo
    echo "Insufficient user privilege."
    echo
    exit 1
fi
#
# Check if PowerPath is active
#
lsmod | grep -w '^emcp' > /dev/null 2>&1
if [ $? -ne 0 ]
then
    echo "PowerPath modules are not loaded"
    echo "Ensure that the modules are loaded and try again"
    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 ~ /dead/ && $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
}'

