Gawk 3.1.1 - Question regarding a variable in a print statement and help with code 
Author Message
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Hello everyone. For fun i am working on a little awk script that will
hopefully log onto my mail server scan each message and print out a
list of each messages Date, From, and Subject line. The code i have
now does not work and i am looking for some advice as to what might be
done to make it work.

BEGIN {
       POPService = "/inet/tcp/0/my.mailserver.com/110"
       RS = ORS = "\r\n"
       print "user myname"  |& POPService
       POPService  |& getline
       print "pass mypass"  |& POPService
       POPService  |& getline
       do {
          count = 1
          print "retr count"  |& POPService
          POPService  |& getline
          RS = "\r\n\\. \r\n"
          POPService  |& getline
          print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e
'/^Date/p'"
          count++
          } while($1 != "-ERR")
       close(POPService)

Quote:
}

the script seems to just sit there and not process anything past the
user and pass section. i think that the problem comes from the line
"print "retr count"" . I have been working on this for a while now and
dont seem to be gettin anywhere. any and all help would be greatly
appreciated. (point me to some similar sample code etc ) thank you for
your time.

-chris



Sun, 13 Mar 2005 12:59:30 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:
> Hello everyone. For fun i am working on a little awk script that will
> hopefully log onto my mail server scan each message and print out a
> list of each messages Date, From, and Subject line. The code i have
> now does not work and i am looking for some advice as to what might be
> done to make it work.

> BEGIN {
>        POPService = "/inet/tcp/0/my.mailserver.com/110"
>        RS = ORS = "\r\n"
>        print "user myname"  |& POPService
>        POPService  |& getline
>        print "pass mypass"  |& POPService
>        POPService  |& getline
>        do {
>           count = 1
>           print "retr count"  |& POPService
>           POPService  |& getline
>           RS = "\r\n\\. \r\n"
>           POPService  |& getline
>           print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e
> '/^Date/p'"
>           count++
>           } while($1 != "-ERR")
>        close(POPService)
> }

> the script seems to just sit there and not process anything past the
> user and pass section. i think that the problem comes from the line
> "print "retr count"" . I have been working on this for a while now and
> dont seem to be gettin anywhere. any and all help would be greatly
> appreciated. (point me to some similar sample code etc ) thank you for
> your time.

> -chris

You don't say what platforms you are running on.  The |& operator is not
available on all platforms, such as Win32 (although it works under
Cygwin).  If you're not on Win32 then try printing out the results from
the getlines for user and pass to see if you get sensible results.
Re-post with more details if you still have problems.

HTH
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Sun, 13 Mar 2005 14:00:12 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:
> You don't say what platforms you are running on.  The |& operator is not
> available on all platforms, such as Win32 (although it works under
> Cygwin).  If you're not on Win32 then try printing out the results from
> the getlines for user and pass to see if you get sensible results.
> Re-post with more details if you still have problems.

> HTH

Whoops i thought i covered all the bases. I am running gawk 3.1.1 on a
box with slackware linux version 8.0. i d/l'd and compiled the 3.1.1
version of gawk because the version that comes with slackware doesnt
support the "|&" symbol. when i add "print $0" after the first two
"POPService  |& getline" lines i reciece back "+OK", so i know i am
connecting. i think the probelm somehow lies in the loop. this is
another attempt at solving the same problem with a for() and still no
luck:

BEGIN {
    POPService = "/inet/tcp/0/my.mailserver.com/110"
    RS = ORS = "\r\n"
    print "user myname"         |& POPService
    POPService                  |& getline
    print "pass mypass"    |& POPService
    POPService                  |& getline
    for ( count = 1;$1 != "-ERR"; count++)
    {
        printf ("retr %d\r\n", count)   |& POPService
        POPService                      |& getline
        RS = "\r\n\\. \r\n"
        POPService                      |& getline
        print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e '/^Date/p'"
    }
    close(POPService)

Quote:
}



Sun, 13 Mar 2005 03:15:13 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:
> You don't say what platforms you are running on.  The |& operator is not
> available on all platforms, such as Win32 (although it works under
> Cygwin).  If you're not on Win32 then try printing out the results from
> the getlines for user and pass to see if you get sensible results.
> Re-post with more details if you still have problems.

> HTH

Whoops i thought i covered all the bases. I am running gawk 3.1.1 on a
box with slackware linux version 8.0. i d/l'd and compiled the 3.1.1
version of gawk because the version that comes with slackware doesnt
support the "|&" symbol. when i add "print $0" after the first two
"POPService  |& getline" lines i reciece back "+OK", so i know i am
connecting. i think the probelm somehow lies in the loop. this is
another attempt at solving the same problem with a for() and still no
luck:

BEGIN {
    POPService = "/inet/tcp/0/my.mailserver.com/110"
    RS = ORS = "\r\n"
    print "user myname"         |& POPService
    POPService                  |& getline
    print "pass mypass"    |& POPService
    POPService                  |& getline
    for ( count = 1;$1 != "-ERR"; count++)
    {
        printf ("retr %d\r\n", count)   |& POPService
        POPService                      |& getline
        RS = "\r\n\\. \r\n"
        POPService                      |& getline
        print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e '/^Date/p'"
    }
    close(POPService)

Quote:
}



Sun, 13 Mar 2005 03:17:17 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:



> > Hello everyone. For fun i am working on a little awk script that will
> > hopefully log onto my mail server scan each message and print out a
> > list of each messages Date, From, and Subject line. The code i have
> > now does not work and i am looking for some advice as to what might be
> > done to make it work.

> > BEGIN {
> >        POPService = "/inet/tcp/0/my.mailserver.com/110"
> >        RS = ORS = "\r\n"
> >        print "user myname"  |& POPService
> >        POPService  |& getline
> >        print "pass mypass"  |& POPService
> >        POPService  |& getline
> >        do {
> >           count = 1
> >           print "retr count"  |& POPService
> >           POPService  |& getline
> >           RS = "\r\n\\. \r\n"
> >           POPService  |& getline
> >           print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e
> > '/^Date/p'"
> >           count++
> >           } while($1 != "-ERR")
> >        close(POPService)
> > }

> > the script seems to just sit there and not process anything past the
> > user and pass section. i think that the problem comes from the line
> > "print "retr count"" . I have been working on this for a while now and
> > dont seem to be gettin anywhere. any and all help would be greatly
> > appreciated. (point me to some similar sample code etc ) thank you for
> > your time.

> > -chris

> You don't say what platforms you are running on.  The |& operator is not
> available on all platforms, such as Win32 (although it works under
> Cygwin).  If you're not on Win32 then try printing out the results from
> the getlines for user and pass to see if you get sensible results.
> Re-post with more details if you still have problems.

> HTH
> --
> Peter S Tillier
> "Who needs perl when you can write dc and sokoban in sed?"
> peter{dot}tillier<at>btinternet[dot]com
> To reply direct to me please use the above address
> not the "Reply To" which activates a spam trap.

Whoops i thought i covered all the bases. I am running gawk 3.1.1 on a
box with slackware linux version 8.0. i d/l'd and compiled the 3.1.1
version of gawk because the version that comes with slackware doesnt
support the "|&" symbol. when i add "print $0" after the first two
"POPService  |& getline" lines i reciece back "+OK", so i know i am
connecting. i think the probelm somehow lies in the loop. this is
another attempt at solving the same problem with a for() and still no
luck:

BEGIN {
    POPService = "/inet/tcp/0/my.mailserver.com/110"
    RS = ORS = "\r\n"
    print "user myname"         |& POPService
    POPService                  |& getline
    print "pass mypass"    |& POPService
    POPService                  |& getline
    for ( count = 1;$1 != "-ERR"; count++)
    {
        printf ("retr %d\r\n", count)   |& POPService
        POPService                      |& getline
        RS = "\r\n\\. \r\n"
        POPService                      |& getline
        print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e '/^Date/p'"
    }
    close(POPService)

- Show quoted text -

Quote:
}



Sun, 13 Mar 2005 03:23:00 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:



> > Hello everyone. For fun i am working on a little awk script that will
> > hopefully log onto my mail server scan each message and print out a
> > list of each messages Date, From, and Subject line. The code i have
> > now does not work and i am looking for some advice as to what might be
> > done to make it work.

> > BEGIN {
> >        POPService = "/inet/tcp/0/my.mailserver.com/110"
> >        RS = ORS = "\r\n"
> >        print "user myname"  |& POPService
> >        POPService  |& getline
> >        print "pass mypass"  |& POPService
> >        POPService  |& getline
> >        do {
> >           count = 1
> >           print "retr count"  |& POPService
> >           POPService  |& getline
> >           RS = "\r\n\\. \r\n"
> >           POPService  |& getline
> >           print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e
> > '/^Date/p'"
> >           count++
> >           } while($1 != "-ERR")
> >        close(POPService)
> > }

> > the script seems to just sit there and not process anything past the
> > user and pass section. i think that the problem comes from the line
> > "print "retr count"" . I have been working on this for a while now and
> > dont seem to be gettin anywhere. any and all help would be greatly
> > appreciated. (point me to some similar sample code etc ) thank you for
> > your time.

> > -chris

> You don't say what platforms you are running on.  The |& operator is not
> available on all platforms, such as Win32 (although it works under
> Cygwin).  If you're not on Win32 then try printing out the results from
> the getlines for user and pass to see if you get sensible results.
> Re-post with more details if you still have problems.

> HTH
> --
> Peter S Tillier
> "Who needs perl when you can write dc and sokoban in sed?"
> peter{dot}tillier<at>btinternet[dot]com
> To reply direct to me please use the above address
> not the "Reply To" which activates a spam trap.

Whoops i thought i covered all the bases. I am running gawk 3.1.1 on a
box with slackware linux version 8.0. i d/l'd and compiled the 3.1.1
version of gawk because the version that comes with slackware doesnt
support the "|&" symbol. when i add "print $0" after the first two
"POPService  |& getline" lines i reciece back "+OK", so i know i am
connecting. i think the probelm somehow lies in the loop. this is
another attempt at solving the same problem with a for() and still no
luck:

BEGIN {
    POPService = "/inet/tcp/0/my.mailserver.com/110"
    RS = ORS = "\r\n"
    print "user myname"         |& POPService
    POPService                  |& getline
    print "pass mypass"    |& POPService
    POPService                  |& getline
    for ( count = 1;$1 != "-ERR"; count++)
    {
        printf ("retr %d\r\n", count)   |& POPService
        POPService                      |& getline
        RS = "\r\n\\. \r\n"
        POPService                      |& getline
        print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e '/^Date/p'"
    }
    close(POPService)

- Show quoted text -

Quote:
}



Sun, 13 Mar 2005 03:26:09 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

[...]

Quote:

> Whoops i thought i covered all the bases. I am running gawk 3.1.1 on a
> box with slackware linux version 8.0. i d/l'd and compiled the 3.1.1
> version of gawk because the version that comes with slackware doesnt
> support the "|&" symbol. when i add "print $0" after the first two
> "POPService  |& getline" lines i reciece back "+OK", so i know i am
> connecting. i think the probelm somehow lies in the loop. this is
> another attempt at solving the same problem with a for() and still no
> luck:

> BEGIN {
>     POPService = "/inet/tcp/0/my.mailserver.com/110"
>     RS = ORS = "\r\n"
>     print "user myname"         |& POPService
>     POPService                  |& getline
>     print "pass mypass"    |& POPService
>     POPService                  |& getline
>     for ( count = 1;$1 != "-ERR"; count++)
>     {
>         printf ("retr %d\r\n", count)   |& POPService
>         POPService                      |& getline
>         RS = "\r\n\\. \r\n"
>         POPService                      |& getline
>         print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e
'/^Date/p'"
>     }
>     close(POPService)
> }

This almost (!) works for me on Cygwin:

# pop.awk
function callpop(action,actarg) {
      print action" "actarg         |& POPService
      POPService                    |& getline
      if ($1 == "-ERR") { print "Error: "$0; exit }
      print action" "$0

Quote:
}

BEGIN {
    myname = ENVIRON["MYNAME"]
    mypass = ENVIRON["MYPASS"]
    service= ENVIRON["MYSERVICE"]

    RS = ORS = "\r\n"

    POPService = "/inet/tcp/0/"service"/110"
    POPService                  |& getline
    if ($1 != "+OK") { print "Error: "$0; exit }
    print "service "$0

    callpop("user",myname)
    callpop("pass",mypass)
    callpop("stat","")
    print $2
    max = $2
    for ( count = 1; count <= max; count++)
    {
        RS = "\r\n"
        print "retr "count   |& POPService
        POPService                      |& getline
        print "retr "count" "$0
        if ($1 != "+OK") break
        callpop("quit","")

        RS = "\r\n\\.\r\n"
        POPService                      |& getline
        print $0 # | "sed -n -e '/^From/p' -e '/^Subject/p' -e
'/^Date/p'"
    }
    close(POPService)

Quote:
}

Where it fails is in printing out all the messages.  The first seems OK
then I just get +OK messages for the others ...

It's off to read the RFC now I guess ...

HTH
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Fri, 18 Mar 2005 14:17:04 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code

Quote:


> [...]

Guys you're just being too fancy..
Get the base to work before worrying about the rest..

This works fine..automating the interaction and parsing the data I leave
to the OP...

function parray(arrname,len, x) {
 while (x <= len) {
 print arrname[x++]
  }
return

Quote:
}

function new_input(str, s) {
printf "RECV-> %s\n :", str
printf "SEND->: "
getline s < "-"
return s

Quote:
}

BEGIN {
  port = 110
  remote = ARGV[1]
  sock = "/inet/tcp/0/" remote "/" port
 while ((sock |& getline) > -1) {
   arr[x++] = $0
   parray(arr,x)
   new = new_input($0)  
   print new |& sock
  }
close(sock)

Quote:
}

Sample run:

+OK POP3 popserv  v7.59 server ready

RECV-> +OK POP3 popserv v7.59 server ready
 :SEND->: user me
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please

RECV-> +OK User name accepted, password please
 :SEND->: pass stuff
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages

RECV-> +OK Mailbox open, 1 messages
 :SEND->: list
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows

RECV-> +OK Mailbox scan listing follows
 :SEND->:
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows
1 770

RECV-> 1 770
 :SEND->: retr 1
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows
1 770
.

RECV-> .
 :SEND->:
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows
1 770
.
-ERR Null command

RECV-> -ERR Null command
 :SEND->: retr 1
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows
1 770
.
-ERR Null command
+OK 770 octets

RECV-> +OK 770 octets
 :SEND->:
+OK POP3 popserv v7.59 server ready
+OK User name accepted, password please
+OK Mailbox open, 1 messages
+OK Mailbox scan listing follows
1 770

+OK 770 octets

Received: from bogus (noway)
        by popserv (8.9.3/8.9.3) with ESMTP id TAA18561

RECV->  by popserv (8.9.3/8.9.3) with ESMTP id TAA18561

Received: from localhost (localhost [127.0.0.1])
        by localhost (Postfix on SuSE Linux 7.2 (i386)) with ESMTP id 6ED68F0282

Content-Type: text/plain;
  charset="us-ascii"


Subject: stuff

etc..



Thu, 24 Mar 2005 07:44:24 GMT  
 Gawk 3.1.1 - Question regarding a variable in a print statement and help with code


Quote:


> > [...]

> Guys you're just being too fancy..
> Get the base to work before worrying about the rest..

> This works fine..automating the interaction and parsing the data I
leave
> to the OP...

> function parray(arrname,len, x) {
>  while (x <= len) {
>  print arrname[x++]
>   }
> return
> }

> function new_input(str, s) {
> printf "RECV-> %s\n :", str
> printf "SEND->: "
> getline s < "-"
> return s
> }

> BEGIN {
>   port = 110
>   remote = ARGV[1]
>   sock = "/inet/tcp/0/" remote "/" port
>  while ((sock |& getline) > -1) {
>    arr[x++] = $0
>    parray(arr,x)
>    new = new_input($0)
>    print new |& sock
>   }
> close(sock)
> }

This also works (now):

# pop.awk
function callpop(action,actarg) {
      print action" "actarg         |& POPService
      POPService                    |& getline
      if (debug) {
        if ($1 == "-ERR") {
          print "Error: "$0
          exit
        }
        print action" "$0
      }

Quote:
}

BEGIN {
    myname = ENVIRON["MYNAME"]
    mypass = ENVIRON["MYPASS"]
    service= ENVIRON["MYSERVICE"]

    RS = ORS = "\r\n"

    POPService = "/inet/tcp/0/"service"/110"
    POPService                  |& getline
    if ($1 != "+OK") { print "Error: "$0; exit }
    if (debug)
      print "service "$0

    callpop("user",myname)
    callpop("pass",mypass)
    callpop("stat","")
    if (debug)
      print $2
    max = $2
    for ( count = 1; count <= max; count++) {
        RS = "\r\n"
        print "retr "count   |& POPService
        POPService           |& getline
        if (debug)
          print "retr "count" "$0
        callpop("","")

        RS = "\r\n\\.\r\n"
        POPService                      |& getline
        print $0 | "sed -n -e '/^From/p' -e '/^Subject/p' -e '/^Date/p'"
    }
    close(POPService)

Quote:
}

Chris and I were both (I think) following the example in the gawk inet
manual which only reads a single message and trying to get it to work
for more than one.  In the event the RFC and your message helped a lot.

Thanks!

Peter
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Thu, 24 Mar 2005 15:40:34 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. accessing a shell variable in an awk print statement

2. a question regarding printing out format

3. Another Newbie question regarding instance variables?

4. Question regarding module variables and thread safety

5. A quick newbie question regarding variables

6. Question regarding variables and after scripts

7. Question regarding mysqldb module and variable table names

8. Question regarding passing variable

9. Recent emails from A. Robbins, regarding latest GAWK (3.0.95)

10. General question re: print statement

11. help redefining print statement

12. need help with counter and print statement

 

 
Powered by phpBB® Forum Software