Operating System - HP-UX
1745832 Members
4136 Online
108723 Solutions
New Discussion

Re: scripting help required

 
SOLVED
Go to solution
zxcv
Super Advisor

scripting help reqd

hi ,

 

Need a help in getting a formated o/p ;

 

 

*** Start of IN635N1 at Tue Sep 25 23:12:19 IST 2012
*** End of IN635N1 at Tue Sep 25 23:12:20 IST 2012 - RC = 0
*** Start of IN9701 at Tue Sep 25 23:12:24 IST 2012
*** End of IN9701 at Tue Sep 25 23:12:26 IST 2012 - RC = 0

I need to grep RC codes from the above file and it must mail me immediately 

14 REPLIES 14
Matti_Kurkela
Honored Contributor

Re: scripting help reqd

#!/bin/sh
SOURCEFILE=/some/file
DESTINATION=zxcv@company.example
SUBJECT="Your RC report"

(printf "%8s %s\n" "Job" "RC"; \
echo "------------"; \ grep -- "- RC =" <"$SOURCEFILE" \ | awk '{printf "%8s %s\n",$4,$15}') \
| mailx -s "$SUBJECT" "$DESTINATION"

 

You specified you want formatted output, but you did not specify the format of the result you wanted.

The above script will produce a mail that will look like this:

 

To: zxcv@company.example
Subject: Your RC report

     Job RC
------------
 IN635N1 0
  IN9701 0

 If this is not what you wanted, please specify the output format you want.

 

MK
zxcv
Super Advisor

Re: scripting help reqd

Hi Matti ,

My o/p file attched herewith.

I want o/p as ;

 

It muxt mail List of job name only other than RC = 0.

 

 

For ex:  

 

IF9591A RC= number ( other than zero )

 

zxcv
Super Advisor

Re: scripting help reqd

PFA o/p file.

 

zxcv
Super Advisor

Re: scripting help reqd

Hi Matti ,

 

Its an online file which gets generated daily from 9pm to 9 am.

How can we grep other than RC = 0 from it and mail it immediately.

Dennis Handly
Acclaimed Contributor

Re: scripting help required

>How can we grep other than RC = 0 from it and mail it immediately.

 

You could do something like:

awk '

BEGIN { start="No previous Start line" }

/Start of/ {

   start = $0 # save

   next

}

/End of/ {

   if ($NF != 0) {  # if RC != 0, print start and stop lines

      print start

      print $0

   }

   next

}' file-name > failures.log

if [ -s failures.log ]; then

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

fi

rm -f failures.log

zxcv
Super Advisor

Re: scripting help required

Hi Dennis ,

 

The o/p is fine.

But say that file gets generated form 9 pm .

I need to put this script in cron right ?

 

It must be run when the input file is getting generated.

Dennis Handly
Acclaimed Contributor

Re: scripting help required

>I need to put this script in cron right?   It must be run when the input file is getting generated.

 

Yes, you could put it in a crontab.  This would mean you don't have to change how the logfile is generated.

Or you could add to the current script to scan and mail it after the file is finished.

zxcv
Super Advisor

Re: scripting help required

Hi Dennis ,

 

One small query , what if i want to grep after this line ;

*** Start of shutcons at Fri Sep 21 21:27:43 IST 2012

 

 

 

and before this line whatevr comes in between.
*** End of CI0251 at Sat Sep 22 03:37:00 IST 2012 - RC = 0

Dennis Handly
Acclaimed Contributor

Re: scripting help required

>what if I want to grep after this line   ...

 

Is this a separate requirement or did you want both at the same time?

If only between those two lines:

awk  '
/Start of shutcons at Fri Sep 21 21:27:43 IST 2012/, \
/End of CI0251 at Sat Sep 22 03:37:00 IST 2012/ {
   print
} ' file-name

 

If it is that simple, you could also use sed.