More busybox awk Q

Denys Vlasenko vda.linux at googlemail.com
Sat Mar 6 01:45:39 UTC 2010


On Friday 05 March 2010 15:47, Yan Seiner wrote:
> This may be somewhat OT, but I've been struggling with this for a 
> while.  I have  an awk script running on an embedded box which 
> periodically sends email.   The email sending part works.  I am having 
> trouble reading the status of the sendmail command.  I need to be able 
> to parse the output of sendmail and look for a "250 OK" to make sure the 
> mail was sent correctly.
> 
> This snippet should work.  Unfortunately on busybox awk piping a shell 
> command to getline doesn't seem to work.  Is this a gawk extension?  Is 
> it unimplemented in busybox?  Or is my syntax wrong?  Regardless, can 
> anyone offer a workaround?

>                         sent = 0
>                         sendmail = "cat /tmp/loc | sendmail -t -v"
>                         while ( sendmail | getline res > 0) {
>                                 if ( res ~ /250 OK/ ) {
>                                         sent = 1
>                                         }
>                                 }
>                         if (sent == 0) {
>                                 print "sending failed"
>                                 }
>                         else {
>                                 print "sent successfully"
>                                 }
>                         close(sendmail)

To my awk-untrained eye it looks to be an obviously malformad program.
I changed it to not run sendmail, but run some echo's, and:

# busybox awk -f PROG
awk: PROG:3: Unexpected token

I added BEGIN { } around it, so that PROG looks like this:

BEGIN {
        sent = 0
        sendmail = "echo 1; echo 250; echo 3 | cat"
        while ( sendmail | getline res > 0 ) {
                if ( res ~ /250/ ) {
                        sent = 1
                        print "sent=1!"
                }
                print "res:", res
        }
        print "end1:", sent
        close(sendmail)
        print "end2:", sent
}

and now it does run, like this:

# busybox awk -f PROG
res: 1
sent=1!
res: 250
res: 3
end1: 1
end2: 1

Does this exact program run for you?
If yes, please run (in shell, not awk):

cat /tmp/loc | strace -oLOGFILE -tt -s99 -f sendmail -t -v

and post resulting LOGFILE.

-- 
vda


More information about the busybox mailing list