*
News: SMF - Just Installed!


Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Look for powered on LPARS and esxi VCenter Guests 1610

Super Newbie Posts: 35 Karma: +3/-0 *
Look for powered on LPARS and esxi VCenter Guests
« on: September 24, 2014, 04:40:45 PM »
I use this via cron every night to make a list of what LPARs and esxi Guests are running.  This is just in case the whole rack goes down.  I can use this output to make sure that everything started up again after the rack comes back up.

This is attached as a file also so you can just download the darn thing.

Comments are welcome.
########################################################################


cat  get_pureflex_guests_and_clients.sh
#!/bin/sh
#######################################################################
#
# Written By: Eric.Wedaa @ Marist.edu
# Copyright (C) 2014  Marist College
# Last Update: 2014-09-18 Added "Assorted Variables" and some notes
#              Added loops instead of making multiple commands
#              2014-09-24 Added call to FSM to get P-Blades
#
#    $Header: /usr/local/sbin/RCS/get_pureflex_guests_and_clients.sh,v 1.5 2014/09/24 20:35:03 root Exp root $
#    $Date: 2014/09/24 20:35:03 $
#    $Revision: 1.5 $
#    $Author: root $
#
#######################################################################
#
# NOTES:  This script is intended to be run from a Linux server that
#         has ssh keys setup to (and sometimes from) the different
#         esxi blades and the FSM
#
#######################################################################
#
# get_pureflex_guests_and_clients.sh - Help figure out what is running
# on your PureFlex
# Copyright (C) 2014  Marist College
# 3399 North Road, Poughkeepsie, NY 12601
#
#  Disclaimer
#
# Marist College makes no representations about the suitability of any of
# the information contained in software programs and related documents
# on the Marist College Freeware Download Page for any purpose. All such
# software programs and related documents are provided without warranty
# of any kind. In no event shall Marist College be liable for damages
# whatsoever, including special, indirect or consequential damages,
# arising out of or in connection with the use or performance of
# information available from the service.

FSM="10.10.5.45" # Could also be hostname.domainname

P_BLADE_NAMES=`ssh USERID@$FSM  'smcli psm lssyscfg -r sys -F name'`

ESXI_BLADES=" dn-pf-esxi1.it.marist.edu \
dn-pf-esxi2.it.marist.edu \
dn-pf-esxi3.it.marist.edu \
dn-pf-esxi4.it.marist.edu \
dn-pf-esxi5.it.marist.edu \
dn-pf-esxi6.it.marist.edu \
dn-pf-esxi7.it.marist.edu \
dn-pf-esxi8.it.marist.edu"

VCENTER_NAME="dn-pf-vcenter"


date
echo "################################################################"
echo "#"
echo "#Getting list of LPARS, (Does not include VIOs)"
echo "#"
echo "###################################################"
for i in $P_BLADE_NAMES ; do
   echo "###############################################"
   echo "#Server name $i"
   echo "#"
   ssh USERID@$FSM "lssyscfg -r lpar -m $i -F lpar_id,primary_state,name"
done

##########################################################################
echo "################################################################"
echo "#"
echo "#Getting list of ESXi Clients"
echo "#"
echo "#Looking for powered on vcenter now"
echo "#"
echo "">/tmp/$$.sh
chown root /tmp/$$.sh
chmod 700 /tmp/$$.sh

for i in $ESXI_BLADES ; do
   #echo "# $i"
   ssh -o ConnectTimeout=10  root@$i vim-cmd vmsvc/getallvms |grep vmx |grep $VCENTER_NAME |awk '{printf ("echo '$i' %d; ssh root@'$i' vim-cmd vmsvc/power.getstate %d \n", $1, $1)}' >>/tmp/$$.sh
done
#echo "Running /tmp/$$.sh now"
sh /tmp/$$.sh |grep -v Retrieved\ runtime\ info
rm /tmp/$$.sh


##########################################################################
echo "#Looking for powered on clients now"
echo "">/tmp/$$.sh
chown root /tmp/$$.sh
chmod 700 /tmp/$$.sh

for i in $ESXI_BLADES ; do
   #echo "# $i"
   ssh -o ConnectTimeout=10  root@$i vim-cmd vmsvc/getallvms |grep vmx |grep -v $VCENTER_NAME |awk '{printf ("echo '$i' %d; ssh root@'$i' vim-cmd vmsvc/power.getstate %d \n", $1, $1)}' >>/tmp/$$.sh
done

sh /tmp/$$.sh |grep -v Retrieved\ runtime\ info

rm /tmp/$$.sh
[root@cfg sbin]#