#!/bin/sh

G_REMOTE_TMP_FILE="/tmp/tmpfile"

LOG_FILE="/var/log/inspect.log"
function LOG 
{
    echo [`date`][$$]$@ >> $LOG_FILE
}

ip=$1

if [ "$ip" == "" ];then
   echo "[ERR]Please enter IPddress"
   exit 0
fi

#CMڲ
psinfo=$(ps -C snas_cm 2>&1)
iRet=$?
if [ $iRet -ne 0 ];then
    echo "[ERR]Failed to execute(ps -C snas_cm) command."
    exit 0
fi
cmExist=$(echo "${psinfo}" | grep "snas_cm")
if [ "X$cmExist" == "X" ]; then
    LOG "[$LINENO]CM is not running." 
    echo "[ERR]CM may not be running."
    exit 0
fi

#ִmmlcmip
/opt/huawei/snas/script/inspect_mml/ShowInspectMml $ip 4016 "cm master"> $G_REMOTE_TMP_FILE[ShowCMMaster] 2>&1
iRet=$?
if [ $iRet -ne 0 ]; then
    LOG "[ShowCMMaster]ShowInspectMml $ip 4016 "cm master" fail." 
    echo "[ERR]ShowInspectMml $ip 4016 "cm master" exe fail." 
    exit 0
fi

MasterID=`cat $G_REMOTE_TMP_FILE[ShowCMMaster] | grep "MasterID" | awk '{ print $4 }'` 2>&1
echo "CMMasterNID: $MasterID"

if [ "$MasterID" == "" ];then
    cat $G_REMOTE_TMP_FILE[ShowCMMaster] >> $LOG_FILE  2>&1 
fi

exit 0


