Hi All,
Need urgent help with korn shell script, which monitors AIX WPARs Status. Basically WPARs run on a LPAR, So there is a Command "lswpar" which displays WPARs status. This script should be checking the WPARs Status and email support if WPAR is down or broken. General lswpar output is as below, I just need the script to check the "Name" and "State" coloumn below, If State is A Server is Active, If State is B Server is Broken, If State is T server is in Transition, If State is D Server is Defined. Script should check the State if its "A" send mail saying State Active with Server Names, If State is B, T, D scricpt should mail saying State Broken or Transition or Defined with Server Names. Please see below for script i tried so far, which is giving error as awk: Field is not correct.
The input line number is 1. The file is /tmp/wpar_state_ck.out.
The source line number is 1.
wpar_status_check_workinprogress[29]: A: bad number
lswpar command output below:
root@wparsprd01:/#lswpar
Name State Type Hostname Directory RootVG WPAR
-----------------------------------------------------------------------
usprd02 A S usprd02 /wpars/usprd02 yes
usprd03 A S usprd03 /wpars/usprd03 yes
usprd03 B S usprd03 /wpars/usprd03 yes
usprd03 T S usprd03 /wpars/usprd03 yes
usprd03 D S usprd03 /wpars/usprd03 yes
Script below:
#!/usr/bin/ksh
#set -x
state=A
echo "************************ WPAR Clients Status Check **************************" >> /tmp/wpar_state_ck.out
echo "--------------------------------------------------------------------------------" >> /tmp/wpar_state_ck.out
lswpar | grep -e Name -e State | awk '{print $1,"\t","\t","\t",$2}' >> /tmp/wpar_state_ck.out
echo "--------------------------------------------------------------------------------" >> /tmp/wpar_state_ck.out
lswpar | awk '{print $1,"\t",$2}' | grep -v Name | grep A >> /tmp/wpar_state_ck.out
# Mail the Status with State Active if A or (Defined or Transition or Broken) if D, T, B
cat /tmp/wpar_state_ck.out | grep -e A | grep -v WPAR | grep -v State | awk '{print $2}' | wc -l | while read i
do
check=$(awk 'FNR == $i {print}' /tmp/wpar_state_ck.out)
if [ "$check" = "$state" ];
then
echo "******************************* WPAR_State = Active *********************************" >> /tmp/wpar_state_ck.out
else
echo "****************** WPAR_State = Defined or Transition or Broken *********************" >> /tmp/wpar_state_ck.out
fi
done
#echo "################################################################################" >> /tmp/wpar_state_ck.out
#echo "A : Active State" >> /tmp/wpar_state_ck.out
#echo "D : Defined State" >> /tmp/wpar_state_ck.out
#echo "T : Transition State" >> /tmp/wpar_state_ck.out
#echo "################################################################################" >> /tmp/wpar_state_ck.out
cat /tmp/wpar_state_ck.out | mail -s "WPAR `hostname` Server monitoring Status of Client WPARs" unix_support@xyz.com
# remove the file
rm -f /tmp/wpar_state_ck.out
Error Message am getting:
awk: Field is not correct.
The input line number is 1. The file is /tmp/wpar_state_ck.out.
The source line number is 1.
wpar_status_check_workinprogress[29]: A: bad number