#!/bin/bash
# get_status.sh -  returns the status of a pServer, given the LPAN and pServer

#called as:
# get_status.sh pServer LPAN_Name UP
# or
# get_status.sh pServer LPAN_Name DOWN
#depending on what you want.  This only works of the pServer is running the PAN Agent
#because until the agent comes up, the server does not count as "Up"

if [ ${3} = "UP" ]
then
        CONDITION=`/opt/panmgr/bin/esh pserver -l ${2}/${1} | grep ^${1} | grep "Booted" | grep "Up"`
        if [ -z "${CONDITION}" ]
        then
                echo "Down" # No Joy
        else
                echo "Up" # Joy!
        fi
else # it should be the case that ${3} = "DOWN"
        CONDITION=`/opt/panmgr/bin/esh pserver -l ${2}/${1} | grep ^${1} | grep "Shutdown"`
        if [ -z "${CONDITION}" ]
        then
                echo "Up" #  No Joy
        else
                echo "Down" # Joy!
        fi
fi

