Operating System - HP-UX
1753674 Members
5442 Online
108799 Solutions
New Discussion

Re: send mail immediately when output arrives in a file

 
SOLVED
Go to solution
zxcv
Super Advisor

send mail immediately when output arrives in a file

Hi  guys ,

 

i have the following awk script which gives me o/p as desired ,

 

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

 

it fills failures.log with RC codes !=0 when shutcon job is started and before CI0251 job.

 

Now my problem is i want to fire a mail immediately when line number 1 gets o/p say for ex:

job xyz RC=12  ( it must send me a mail )

 

Afetr 2 min whan another line comes say for ex:

job tes RC=64 ( it must send me a mail )

 

Note here i shuld be getting 2 different mails with a single line only.

i.e it must flush earlier mailed line.

 

abc.log file is getting  updated throughout day.

4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: send mail immediately when output arrives in a file

There are several ways to do this.

You could redirect awk's stdout to a named pipe.  Then have another script read the pipe and send mail for each line.

(Or you could have coprocesses instead of that named pipe.)

 

Or you could replace that print by a open-print-close to a file.  And then invoke the system function to mail that file.

Dennis Handly
Acclaimed Contributor

Re: send mail immediately when output arrives in a file

>Or you could replace that print by a open-print-close to a file.  ...

 

Actually it is simpler than that:

awk  '

BEGIN { mail_it = "mailx -s \"subject\" zxcv@company.example" }
/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 | mail_it

      close(mail_it)
   }
}' abc.log

Dennis Handly
Acclaimed Contributor
Solution

Re: send mail immediately when output arrives in a file

>abc.log file is getting updated throughout day.

 

I assume you know you still need to use something like Laurent's solution in your other topic:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/Initiate-a-script-for-a-pattern-grepped-in-a-file/m-p/5833257

zxcv
Super Advisor

Re: send mail immediately when output arrives in a file

Thanks a ton