Operating System - HP-UX
1748359 Members
5440 Online
108763 Solutions
New Discussion

Re: Help reqd for scripting

 
SOLVED
Go to solution
zxcv
Super Advisor

Help reqd for scripting

Hi Dennis , 

My reqmnt is as follows;

 

a logfile gets generated at 9 pm say abc.log which contains a line ;

 

Start of shutcons 

 

i want to capture RC codes for all jobs afetr this line  , and it must fire a mail grepping RC other than zero codes , till i get a line given below in my dynamically generating log file  ;

 

End of CI0251

 

Sample of abc.log file is afollows ;

 

Start of shutcons at  Tue Sep 25 21:28:40 IST 2012

 

*** End   of shutcons at  Tue Sep 25 21:28:40 IST 2012  - RC =  0

*** Start of  SY9600  at  Tue Sep 25 21:29:05 IST 2012

*** End   of  SY9600  at  Tue Sep 25 21:29:05 IST 2012  - RC =  0

*** Start of shutcons at  Tue Sep 25 21:29:06 IST 2012

 

*** End   of shutcons at  Tue Sep 25 21:29:06 IST 2012  - RC =  0

*** Start of hksh0004 at  Tue Sep 25 21:29:12 IST 2012

 

*** End   of hksh0004 at  Tue Sep 25 21:29:12 IST 2012  - RC =  0

*** Start of shutbtm at  Tue Sep 25 21:29:19 IST 2012

 

*** End   of shutbtm at  Tue Sep 25 21:29:19 IST 2012  - RC =  0

*** Start of stopgateway at  Tue Sep 25 21:29:37 IST 2012

 

*** End   of stopgateway at  Tue Sep 25 21:29:38 IST 2012  - RC =  0

*** Start of shutbtm at  Tue Sep 25 21:29:40 IST 2012

 

*** End   of shutbtm at  Tue Sep 25 21:29:40 IST 2012  - RC =  0

*** Start of  UTDEBUG1  at  Tue Sep 25 21:29:41 IST 2012

*** End   of  UTDEBUG1  at  Tue Sep 25 21:29:41 IST 2012  - RC =  0

*** Start of hkcheckdf at  Tue Sep 25 21:29:43 IST 2012

 

*** End   of hkcheckdf at  Tue Sep 25 21:29:43 IST 2012  - RC =  0

*** Start of chkrerun at  Tue Sep 25 21:29:47 IST 2012

 

*** End   of chkrerun at  Tue Sep 25 21:29:47 IST 2012  - RC =  0

*** Start of  SY0007  at  Tue Sep 25 21:29:53 IST 2012

*** End   of  SY0007  at  Tue Sep 25 21:29:54 IST 2012  - RC =  0

*** Start of  SY3100  at  Tue Sep 25 21:30:12 IST 2012

*** End   of  SY3100  at  Tue Sep 25 21:30:12 IST 2012  - RC =  0

*** Start of  SP0100  at  Tue Sep 25 21:30:13 IST 2012

*** End   of  SP0100  at  Tue Sep 25 21:30:35 IST 2012  - RC =  0

*** Start of spms0122 at  Tue Sep 25 21:30:36 IST 2012

 

*** End   of spms0122 at  Tue Sep 25 21:31:07 IST 2012  - RC =  0

*** Start of  SY9507  at  Tue Sep 25 21:31:08 IST 2012

*** End   of  SY9507  at  Tue Sep 25 21:31:11 IST 2012  - RC =  0

*** Start of stopgateway at  Tue Sep 25 21:31:16 IST 2012

 

*** End   of stopgateway at  Tue Sep 25 21:31:16 IST 2012  - RC =  0

*** Start of shutbtm at  Tue Sep 25 21:31:17 IST 2012

 

*** End   of shutbtm at  Tue Sep 25 21:31:17 IST 2012  - RC =  0

*** Start of  SY9600  at  Tue Sep 25 21:31:18 IST 2012

*** End   of  SY9600  at  Tue Sep 25 21:31:18 IST 2012  - RC =  0

*** Start of  UTDEBUG1  at  Tue Sep 25 21:31:19 IST 2012

*** End   of  UTDEBUG1  at  Tue Sep 25 21:31:19 IST 2012  - RC =  0

*** Start of  SY0007  at  Tue Sep 25 21:31:27 IST 2012

*** End   of  SY0007  at  Tue Sep 25 21:31:27 IST 2012  - RC =  04

*** Start of  SY3300  at  Tue Sep 25 21:31:47 IST 2012

*** End   of  SY3300  at  Tue Sep 25 21:31:47 IST 2012  - RC =  0

*** Start of  SY0199  at  Tue Sep 25 21:31:56 IST 2012

*** End   of  SY0199  at  Tue Sep 25 21:31:56 IST 2012  - RC =  254

 

End of CI0251

 

It must fire a mail saying job sy0199 RC = 254

It must fire a mail saying job sy0007 RC = 04 immediately as it comes in abc.log file.

Dennis Handly
Acclaimed Contributor

Re: Help reqd for scripting

awk  '
/Start of shutcons/, /End of CI0251/ {
   if ($2 == "End" && $3 == "of" && $NF != 0) {
      # if RC != 0, print stop line
      print "job", $4, $(NF-2), "=", $NF
   }
} ' abc.log > failures.log

if [ -s failures.log ]; then

   mailx -s "subject" zxcv@company.example < failures.log

fi

rm -f failures.log



zxcv
Super Advisor

Re: Help reqd for scripting

Hi ,

 

Dennis ,

 

i tried the above script , but was not able to grep RC code 12 from the below lines;

 

*** Start of shutcons at Wed Oct 10 00:30:17 IST 2012

*** End of shutcons at Wed Oct 10 00:30:18 IST 2012 - RC = 0

*** End of SY0331 at Wed Oct 10 01:23:17 IST 2012 - RC = 0
*** Start of BR2490 at Wed Oct 10 01:23:23 IST 2012
*** End of BR2490 at Wed Oct 10 01:23:36 IST 2012 - RC = 0
*** Start of cfps0201 at Wed Oct 10 01:23:38 IST 2012

*** End of cfps0201 at Wed Oct 10 01:23:38 IST 2012 - RC = 0
*** Start of SY0201 at Wed Oct 10 01:23:39 IST 2012
*** End of SY0201 at Wed Oct 10 01:23:39 IST 2012 - RC = 12
*** Start of IN0787 at Wed Oct 10 01:23:40 IST 2012
*** End of IN0787 at Wed Oct 10 01:23:40 IST 2012 - RC = 0
*** Start of CI0251 at Wed Oct 10 01:23:43 IST 2012
*** End of CI0251 at Wed Oct 10 01:23:52 IST 2012 - RC = 0

 

Dennis Handly
Acclaimed Contributor

Re: Help reqd for scripting

>I tried the above script , but was not able to grep RC code 12 from the below lines;

 

*** Start of shutcons at Wed Oct 10 00:30:17 IST 2012

...

*** End of CI0251 at Wed Oct 10 01:23:52 IST 2012 - RC = 0

 

From your example file, I assumed that the start and ending strings didn't have leading "***".  So change to:

/Start of shutcons/, /End of CI0251/ {

  

zxcv
Super Advisor
Solution

Re: Help reqd for scripting

Hi Dennis ,

 

Thanks very much.