#!/bin/bash

# September 2007, Dominik Klein
# Display scores of Linux-HA resources
# September 2007, Robert Lindgren
# Change echo to printf

printf "%-20s%-20s%-20s%-20s\n" Resource Node Score [target_role]
2>&1 ptest -LVVVVVVV|grep -E "assign_node|rsc_location"|grep -w -E "\ [-]{0,1}[0-9]*$"|while read line
do
	node=$(echo $line|cut -d ' ' -f 8|cut -d ':' -f 1)
	res=$(echo $line|cut -d ' ' -f 6|tr -d ",")
	score=$(echo $line|cut -d ' ' -f 9)
	targetrole=$(cibadmin -Q|grep $res|grep target_role|grep -o -E 'value=".*"'|cut -d '"' -f 2|grep -i stopped)
	if [ "$targetrole" = "stopped" ]
	then 
		echo Score of -1000000 is intentional when target_role=\"stopped\"
	fi
  printf "%-20s%-20s%-20s%-20s\n" "$res" "$node" "$score" "$targetrole"
#	echo -e a$res\\t$node\\t$score\\t$targetrole
done|sort -k 1|uniq
