mail command within awk #2

  • Follow


Hi ,

 Shall we run the mail command within awk based on some condition. Can
anyone help me in this.

Thanks & Regards,
Gopi

0
Reply gopikrishnan.gunasekaran (19) 2/9/2006 6:03:04 PM

gopikrishnan.gunasekaran@gmail.com wrote:
> Hi ,
> 
>  Shall we run the mail command within awk based on some condition. Can
> anyone help me in this.
> 
> Thanks & Regards,
> Gopi
> 

It isn't clear what you're asking. If, for example, you're asking how to 
execute the UNIX mailx command from within awk, the responses you'd get 
would be:

a) There's probably a better way to achieve your goal than to do that.
b) The answer will be platform-specifc and so the question should be 
asked in a platform-specific newsgroup, e.g. comp.unix.shell

Regards,

	Ed.
0
Reply Ed 2/9/2006 11:47:47 PM


gopikrishnan.gunasekaran@gmail.com wrote:
> Hi ,
> 
>  Shall we run the mail command within awk based on some condition. Can
> anyone help me in this.
> 
> Thanks & Regards,
> Gopi
> 

There's the possibility to pipe any string to an external command, and
before that you may also extract subject and mail address information...

/some subject condition/ { subject = $4 }
/some recipient condition/ { addrlist = addrlist " " $1 }
/some content condition/ { print $5 $6 | "mailx -s " subject addrlist }

If, OTOH, just the mail body is to be defined by the awk data then you
could put that shell interface to the shell level...

awk '/some content cond/ { print $5 $6 }' yourdata | mailx -s subj x@y.z


Janis
0
Reply Janis 2/10/2006 12:41:25 AM

On Thu, 9 Feb 2006, gopikrishnan.gunasekaran@gmail.com wrote:

>  Shall we run the mail command within awk based on some condition. Can
> anyone help me in this.

I have some scripts who mail me (once) if they detect some condition 
(repeatedly). E.g. a crontab script who periodically runs ps and informs 
me of any new process started by an unusual user.

When I detect the condition I do something like this (the counter ne is 
initialized at zero)

  s="my own specific message on the condition"
  ne++ 
  mail(s) 

where mail(s) is a function defined at the end of the file, which 
appends the string to a file (fil3 is initialized at beginning)

    function mail(string) { print string >> fil3  }

The way I do the mailing is the following invocation (at the end of the 
main clause ... such scripts for me have usually just a BEGIN clause)

if (ne > 0) system("/usr/bin/mailx -s 'mysub' myaddr < "fil3" >/dev/null")   

where mysub is a string which goes in the subject, and myaddr is my own 
e-mail address.


-- 
----------------------------------------------------------------------
nospam@mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
0
Reply LC 2/16/2006 1:20:22 PM

3 Replies
289 Views

(page loaded in 0.065 seconds)

Similiar Articles:













7/23/2012 9:24:54 PM


Reply: