#!/bin/bash

connlist=`LANG=en_US lssysconn -r all -Fipaddr:state:resource_type`
if [ $? -eq 0 ]; then
   if [ "$connlist" != "No results were found." ]; then
     for i in $connlist
     do
       ip=`echo $i | cut -d':' -f1`
       state=`echo $i | cut -d':' -f2`
       type=`echo $i | cut -d':' -f3`
       if [[ "$state" == "Connected" || "$state" == "Pending Authentication - Password Updates Required" || "$state" == "Failed Authentication" ]]; then
          if [[ "$type" == "sys" && "$ip" == "$1" ]]; then
  	     /opt/hsc/bin/hmcBrowserLaunch https://$1
	     exit 0
          fi
       fi 
     done
   fi
fi
/opt/hsc/bin/isSP $1 >/dev/null 2>&1
if [ $? -eq 1 -o $? -eq 2 ]; then
   /opt/hsc/bin/hmcBrowserLaunch https://$1
   exit 0
fi
exit 1
