# Dell LCD Update .2
# Nicholas Weaver - www.nickapedia.com
# 1-4-2008

# .2 - changed vmlist to use vmware-vim-cmd. This gives the actual VM name instead of the VMX file name


while [ 1 ]
do
vmlist=(`vmware-vim-cmd  vmsvc/getallvms | grep -v "Name" | awk '{print $2}'`)
### vmlist=(`vmware-cmd -l | awk -F'/' '{sub(/.vmx/,"");print $NF}'`) - Old style
vmcount=${#vmlist[@]}
vmfile='/etc/lcd_vm_index'
unset cmdstring

if [ -f $vmfile ];
then
   vmindex=`cat $vmfile`
   vmindex=`expr $vmindex + 1`
      if [ $vmindex -gt $vmcount ]
	then
	  vmindex=1
	fi
   echo $vmindex > $vmfile
else
   vmindex=1
   echo $vmindex > $vmfile
fi
vmindex=`expr $vmindex - 1`


if [ $vmcount = 0 ]
then
	var=`hostname | awk -F'.' '{print $1}'`
else
	var=${vmlist[$vmindex]}
fi

varlist=(`echo $var | xxd -g 1 -c 1 | awk '{print $2}' | grep -v "0a" | awk '{print "0x"$1}'`)

for ((i=0;i<=13;i+=1)); do
	char=${varlist[$i]}
	if [ -z $char ]
		then
			cmdstring=$cmdstring' 0x20'
		else
			cmdstring=$cmdstring' '$char
		fi
done

#echo ipmitool raw 0x6 0x58 193 $chunk 0 14 $cmdstring
echo LCD Message is: $var with the index of $vmindex
/usr/local/bin/ipmitool raw 0x6 0x58 193 0 0 14 $cmdstring
/usr/local/bin/ipmitool raw 0x6 0x58 194 0
sleep 8
done

