Scripts for AIX refresh dconsole and dsh

NIM installation scripts

Read the HMC config and add all partition to dconsole config file, and to DSH config file.

dsh command is a parallel shell (AIX package dsm.dsh)
dconsole command allows from an AIX server (NIM for example) to open a console on an LPAR using the file /etc/ibm/sysmgt/dsm/config/

refresh_dcons.sh

#!/bin/ksh
#set -x
#@(#) Refresh the node list for dconsole command, and wcoll for dsh
# try : what *
# HMC password file must be located in /etc/ibm/sysmgt/dsm/config/${hmc}_passwd_file
########################################################################
# v1.0 18-11-2015 Manu
# v1.1 09-2016 add dsh list for VIOS

dir=`dirname $0`
. $dir/.env

emailaddr="test@yahoo.com"
hmclist="hmc1 hmc2"
hmcuser=hscroot

dshpath=/root
DSH_NODE_LIST=$dshpath/.dsh_wcoll_all.cfg
DSH_NODE_LIST_LPAR=$dshpath/.dsh_wcoll_lpar.cfg
DSH_NODE_LIST_WPAR=$dshpath/.dsh_wcoll_wpar.cfg
DSH_VIOS_LIST=$dshpath/.dsh_wcoll_vios.cfg
DSH_NODE_LIST_LINUX=$dshpath/.dsh_wcoll_lpar_linux.cfg

DCONSOLE_NODE_LIST=/etc/ibm/sysmgt/dsm/nodeinfo
SSH_BIN='ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR '

#------------------------------------------------
usage()
{
rep=$*
case "$rep" in
help|-h|-help )
        echo "Usage: "$0" (start | stop)"
        exit 1
        ;;
*)
        echo OK
        ;;
esac
}

#------------------------------------------------
refresh_dconsole()
{
rm $logpath/dcons*.log 2> /dev/null

for hmc1 in $(echo $hmclist)
do
  if [ $(ping -c2 $hmc1 > /dev/null 2>&1;echo $?) -eq 0 ]
  then
    hmc=$hmc1
    break
  fi
done

ssh $hmcuser@$hmc 'lssyscfg -r sys -F name,type_model,serial_num,state' > $logpath/dcons1.log

if [ -f $DCONSOLE_NODE_LIST ]
then
  mv $DCONSOLE_NODE_LIST ${DCONSOLE_NODE_LIST}.old
fi

for line in $(cat $logpath/dcons1.log | sort | uniq)
do
  server=$(echo $line | cut -d',' -f1)
  type=$(echo $line | cut -d',' -f2)
  serial=$(echo $line | cut -d',' -f3)
  ssh $hmcuser@$hmc "lssyscfg -r lpar -m $server -F name,lpar_id,lpar_env,state" > $logpath/dcons1.${server}.log
  for line1 in $(cat $logpath/dcons1.${server}.log | sed 's/\ //g')
  do
    lparname=$(echo $line1 | cut -d',' -f1)
    lparid=$(echo $line1 | cut -d',' -f2)
    lparenv=$(echo $line1 | cut -d',' -f3)
    lparstate=$(echo $line1 | cut -d',' -f4)
    echo "${lparname}|hmc|${hmc}|TargetHWTypeModel=${type}:TargetHWSerialNum=${serial}:TargetLPARID=${lparid}|/etc/ibm/sysmgt/dsm/config/${hmc}_passwd_file" >> ${DCONSOLE_NODE_LIST}
    if [ "$lparstate" == "Running" ]
    then
      if [ "$lparenv" == "vioserver" ]
      then
        echo "${lparname}" >> $logpath/dcons_list_vios_running.log
      else
        echo "${lparname}" >> $logpath/dcons_list_running.log
      fi
    fi
  done
done
}

#------------------------------------------------
refresh_dshlist()
{
ALERT=""

rm ${DSH_NODE_LIST_LPAR} ${DSH_NODE_LIST_WPAR} ${DSH_NODE_LIST_LINUX} > /dev/null 2>&1
if [ -f $DSH_NODE_LIST ]
then
  mv $DSH_NODE_LIST ${DSH_NODE_LIST}.old
fi

if [ -f $DSH_VIOS_LIST ]
then
  mv $DSH_VIOS_LIST ${DSH_VIOS_LIST}.old
fi

for node in $(cat $logpath/dcons_list_vios_running.log | sort)
do
  if [ $(${SSH_BIN} -l padmin $node 'ioscli ioslevel' > /dev/null 2>&1;echo $?) -eq 0 ]
  then
    echo "$node" >> ${DSH_VIOS_LIST}
  else
    echo "VIOS: $node doesn't ping"
  fi
done

for node in $(cat $logpath/dcons_list_running.log | cut -d'|' -f1 | sort)
do
  if [ $(${SSH_BIN} $node 'uname -a' | grep -q '^AIX';echo $?) -eq 0 ]
  then
    echo "$node" >> ${DSH_NODE_LIST}
    echo "$node" >> ${DSH_NODE_LIST_LPAR}
    for node1 in $(${SSH_BIN} $node 'lswpar -qca name -sA')
    do
      if [ $(${SSH_BIN} $node1 hostname > /dev/null 2>&1;echo $?) -eq 0 ]
      then
        echo "$node1" >> ${DSH_NODE_LIST}
        echo "$node1" >> ${DSH_NODE_LIST_WPAR}
      else
        echo "$node1 doesn't ping"
      fi
    done
  else
    if [ $(${SSH_BIN} $node 'uname -a' | grep -qi '^linux';echo $?) -eq 0 ]
    then
      echo "$node" >> ${DSH_NODE_LIST_LINUX}
    else
      if [ $(ping -c2 $node > /dev/null 2>&1;echo $?) -eq 0 ]
      then
        echo "$node ping but SSH not working"
        ALERT=$(echo ${ALERT} "$node ping but SSH not working\n")
      else
        echo "$node doesn't ping"
      fi
    fi
  fi
done

if [ "$ALERT" != "" ]
then
  echo $ALERT | mailx -s "Please correct the SSH problems from $(hostname)" $emailaddr
fi
}

#############################################
# main
#############################################
main()
{
date
echo "######### refresh_dconsole"
refresh_dconsole
echo "######### refresh_dshlist"
refresh_dshlist
date
}

main > $logname 2>&1