Need urgent help with korn shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need urgent help with korn shell script
# 1  
Old 10-20-2012
Need urgent help with korn shell script

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

Code:
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:
Code:
#!/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:
Code:
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

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 10-20-2012 at 10:32 PM..
# 2  
Old 10-20-2012
Check out the below code, I believe it will make doing what you want a little simpler:
Code:
$ cat t
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


while read name state type hostname directory rootvg wpar
do
  (( c+=1 ))
  if [[ $c -gt 2 ]]; then
    if [[ $state = "A" || $state = "B" || $state = "D" || $state = "T" ]]; then
      #### your code to handle these states
    fi
  else
    : # no-op
  fi
done <t

This User Gave Thanks to spacebar For This Post:
# 3  
Old 10-20-2012
Agree with spacebar -- can be simplified. My thoughts:

Code:
lswpar  | awk '
    /^Name/ { next; }
    /^---/  { next; }
    { state[$2] = state[$2] $1 " "; }
    END {
        printf( "==== WPAR Status Check =====\n" );
        printf( "**** WPAR state Active:\n\t%s\n\n", state["A"] );
        printf( "**** WPAR state Defined/Transition/broken:\n\t%s %s %s\n", state["D"], state["T"], state["B"] );
    }
' | mail -s "WPAR `hostname` Server monitoring Status of Client WPARs" unix_support@xyz.com

As to the reason for your error, you cannot use a shell variable ($i in this case) like you are attempting (in single quotes shell will not expand it). You could try:

Code:
check=$(awk 'FNR == I {print}'  I=$i  /tmp/wpar_state_ck.out)

But I would try something that is much more straight forward than the way you were approaching it.

Last edited by agama; 10-20-2012 at 11:12 PM.. Reason: fixed cut/paste truncation.
This User Gave Thanks to agama For This Post:
# 4  
Old 10-21-2012
Thanks both spacebar and agama, one small update in script

Thanks both spacebar and agama, you both are saviours, one small update in script.

Am using script suggested by agama:

Script code:
lswpar | awk '
/^Name/ { next; }
/^---/ { next; }
{ state[$2] = state[$2] $1 " "; }
END {
printf( "==== WPAR Status Check =====\n" );
printf( "**** WPAR state Active:\n\t%s\n\n", state["A"] );
printf( "**** WPAR state Defined/Transition/broken:\n\t%s %s %s\n", state["D"], state["T"], state["B"] );
}
' | mail -s "WPAR `hostname` Server monitoring Status of Client WPARs" unix_support@xyz.com

Current Mail Output from script:
==== WPAR Status Check =====
**** WPAR state A-Active:
usprd02 usprd03 usprd04 usprd05 usprd06

**** WPAR state D-Defined/T-Transition/B-broken:

I need below required output:
If All WPARs are Active, below output:

==== WPAR Status Check =====

**** WPAR state A-Active:
usprd02 usprd03 usprd04 usprd05 usprd06

All WPARs are in Active State

No Defined/Transition/Broken WPARs

If 2 WPARs are Active, and 3 are Defined/Transition/Broken each, below output:

==== WPAR Status Check =====

**** WPAR state A-Active:
usprd02 usprd03

2 WPARs are in Active State

**** WPAR state D-Defined/T-Transition/B-broken:
usprd04 usprd05 usprd06

3 WPARs are in Defined/Transition/Broken State






Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

3. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

4. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

5. Shell Programming and Scripting

Urgent Korn Shell scripting Help Pleaaaase...

Hello All, Can someone help me to set a user's password from the script using korn shell. The password change is a one time password after user account creation. I tried providing the input file as the value for password field but password change requires tty so my password from an input file... (3 Replies)
Discussion started by: solaix14
3 Replies

6. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

7. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

8. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies

9. UNIX for Advanced & Expert Users

Minesweeper in korn shell:urgent

if you have the programme of Minesweeper;take me it because i need it. thank u very much. (1 Reply)
Discussion started by: raul
1 Replies

10. UNIX for Advanced & Expert Users

demineur in korn shell:urgent.

hello. have please a demineur programmed in shell korn (unix).???? can you send it to me??? thanks. (0 Replies)
Discussion started by: raul
0 Replies
Login or Register to Ask a Question