From: mo on
The script works fine for this server/group! :)

On Mon, 05 May 2008 00:35:24 -0300, mo <invalid(a)mail.address> wrote:

> The script below is to get latest posts from a newsgroup via nntp.
> It uses just bash.
> If you post a message and run this script after few seconds I think
> the probability of your message be the last is great.
From: mo on
Sorry, better add more information about my test:

$ getnews
LL=27599
LP=27600
/tmp/comp.unix.shell.27599
/tmp/comp.unix.shell.27600
$

$ cat /tmp/comp.unix.shell.27600
Path: aioe.org!not-for-mail
From: mo <invalid(a)mail.address>
Newsgroups: comp.unix.shell
Subject: Re: Usenet server test script
Date: Mon, 05 May 2008 00:35:24 -0300
Organization: Aioe.org NNTP Server
Lines: 88
Message-ID: <op.uanv9azp37fkpp(a)k7>
References: <egdr149mrt38s127jp8aq6ufu4h7j3pjg7(a)4ax.com>
NNTP-Posting-Host: wNGoEd4W65tH4++WxTvI1A.user.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Content-Transfer-Encoding: Quoted-Printable
X-Complaints-To: abuse(a)aioe.org
User-Agent: Opera Mail/9.27 (Linux)
Xref: aioe.org comp.unix.shell:27600

The script below is to get latest posts from a newsgroup via nntp.
It uses just bash.
If you post a message and run this script after few seconds I think
the probability of your message be the last is great.
In anyway the value of the var "REPLY" has more info than...
....
etc.
....
> Organization: scriptpost
> Message-ID: <$id(a)post.invalid>
>
> test $id
> %end




--------------------------------
On Mon, 05 May 2008 00:41:24 -0300, mo <invalid(a)mail.address> wrote:

> The script works fine for this server/group! :)
>
> On Mon, 05 May 2008 00:35:24 -0300, mo <invalid(a)mail.address> wrote:
>
>> The script below is to get latest posts from a newsgroup via nntp.
>> It uses just bash.
>> If you post a message and run this script after few seconds I think
>> the probability of your message be the last is great.

From: Dan Stromberg on
On Mon, 05 May 2008 02:01:58 +0000, Kenny McCormack wrote:

> In article <66vr145h4fub9ks0l6depgs62rnjlfnoar(a)4ax.com>, Dave Farrance
> <DaveFarrance(a)OMiTTHiSyahooANDTHiS.co.uk> wrote: ...
>>Thanks for the reply. I've installed tcp [TCL] and expect, but I find
>>the expect manpage to be hard reading. I've managed to get it to
>>display a post, although I don't really know how to separate the server
>>messages from the post. The "interact" tells it to display everything,
>>and it does exit without user intervention, but I'm sure there's a
>>neater way.
>
> Expect is a little hard going, but learning it is absolutely essential
> if you want to consider yourself a Unix scripting guy. The book
> "Exploring Expect" (by Don Libes, author of Expect) is absolutely
> essential.

Disagree - there's always a cleaner way than expect, and when the
immediacy of the need does actually dictate use of a pty, I think it
makes more sense to use a language like python with the pexpect or pty
modules - I tend to opt for the pty module. But it's still like going to
war - sometimes there's no other way (The Khmer Rouge wasn't going to
stop just because someone asked them nicely), but that doesn't mean it's
a pleasant option.

I know there are expect fans in the world. I'm not one of them. And
it's so far from essential. It never really was.

In this case, telnet is pretty unnecessarily clunky - it'd be better to
at least use netcat, or much better to use a socket module in python or
perl, or better still to use an nntp-specific module in same.

From: Stephane CHAZELAS on
2008-05-05, 17:25(+00), Dan Stromberg:
[...]
> In this case, telnet is pretty unnecessarily clunky - it'd be better to
> at least use netcat, or much better to use a socket module in python or
> perl, or better still to use an nntp-specific module in same.

Note that expect is a TCL interpreter with some additions for
/expecting/ outputs of commands with the use of ptys. But it
doesn't have to /expect/ on a pty, it can /expect/ on any file
descriptor like a socket.

TCL has the "socket" function for TCP sockets. See socket(3tcl).

expect -c 'spawn -open [socket server nntp]...'

Nowadays, the /expecting/ features found of expect have been
packaged in a libexpect and made available to other interpreters
such as perl.

--
St�phane
From: Theo v. Werkhoven on
The carbonbased lifeform Dave Farrance inspired comp.unix.shell with:
> "Theo v. Werkhoven" <theo(a)van-werkhoven.nl.invalid> wrote:
>
>>Sure there is.
>>$telnet news.xs4all.nl 119
>>Trying 194.109.133.242...
>>Connected to news.xs4all.nl.
>>Escape character is '^]'.
>>200 news.xs4all.nl NNRP Service Ready (posting ok).
>>article <l3kr14d2fhvghmla9rdh0ia12cupsq2fqs(a)4ax.com> /* my command */
>>220 0 <l3kr14d2fhvghmla9rdh0ia12cupsq2fqs(a)4ax.com> article
>>Path: news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.xs4all.nl...
>>...
>>With 'article' you get the post with the requested Message-ID.
>>Now write a little expect script and you're done.
>
> Thanks for the reply. I've installed tcp and expect, but I find the
> expect manpage to be hard reading. I've managed to get it to display a
> post, although I don't really know how to separate the server messages
> from the post. The "interact" tells it to display everything, and it
> does exit without user intervention, but I'm sure there's a neater way.

You're right, expect(1) /is/ difficult to read if you have no
experience with expect yet.

With 'body' instead of 'article' it skips the headers. Is that what you
mean by 'server messages'?

>
> #!/usr/bin/expect -f
> spawn telnet aioe.cjb.net 119
> sleep 1
> send "article <0123456789abcdef(a)foo.invalid>\r"
> sleep 1
> send "quit\r"
> interact

Put this in a script called e.g. 'newsbody.exp' and make it executable
#v+
!/usr/bin/expect --
spawn telnet [lindex $argv 0 ] 119
expect -re "200(.*)$"
send "body [lindex $argv 1]\r"
expect -timeout 1 -re "^\.$"
send "quit\r"
#v-

Use as:
newsbody.exp "server.address.tld" "Message_ID" >testout.txt

Theo
--
theo at van-werkhoven.nl ICQ:277217131 SuSE Linux
linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
de uitwassen *van* Microsoft"