PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Usenet server test script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Usenet server test script

Réponse
 
LinkBack Outils de la discussion
Vieux 04/05/2008, 14h37   #1
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Usenet server test script

Below is a script that posts a test message via a public newserver and
provides a randomly generated title and Message-ID. It uses the "rpost"
command, which is included in the "suck" package to post the message.

I'd like to add a "suck" command to the script to read the message back
from the server, using the specified Message-ID, and to display that
message. I guess I'll figure out how to do it eventually, but the "suck"
command seems to be far more complex than "rpost" and it requires config
files. There's no easy way to do this that I'm missing, is there?


#!/bin/bash
newsserver=aioe.cjb.net
id=$(od -xvAn -N8 < /dev/urandom | tr -cd 0-9a-f)
rpost $newsserver <<%end
From: scriptpost <script@post.invalid>
Newsgroups: alt.test
Subject: TEST-$id
Organization: scriptpost
Message-ID: <$id@post.invalid>

test $id
%end
  Réponse avec citation
Vieux 04/05/2008, 16h17   #2
Theo v. Werkhoven
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

The carbonbased lifeform Dave Farrance inspired comp.unix.shell with:
> Below is a script that posts a test message via a public newserver and
> provides a randomly generated title and Message-ID. It uses the "rpost"
> command, which is included in the "suck" package to post the message.
>
> I'd like to add a "suck" command to the script to read the message back
> from the server, using the specified Message-ID, and to display that
> message. I guess I'll figure out how to do it eventually, but the "suck"
> command seems to be far more complex than "rpost" and it requires config
> files. There's no easy way to do this that I'm missing, is there?


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@4ax.com> /* my command */
220 0 <l3kr14d2fhvghmla9rdh0ia12cupsq2fqs@4ax.com> article
Path:
news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.x s4all.nl!newsfeed2.news.
xs4all.nl!xs4all!feeds.phibee-telecom.net!news.mixmin.net!eweka.nl!hq-usenetpeer
s.eweka.nl!69.16.177.246.MISMATCH!cyclone03.ams!ne ws.ams.newshosting.com!npeersf
01.ams!newsfe30.ams2.POSTED!53ab2750!not-for-mail
From: The Beloved <maybe@one.day>
Newsgroups: nl.comp.hardware

With 'article' you get the post with the requested Message-ID.
Now write a little expect script and you're done.

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"
  Réponse avec citation
Vieux 04/05/2008, 19h47   #3
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

"Theo v. Werkhoven" <theo@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@4ax.com> /* my command */
>220 0 <l3kr14d2fhvghmla9rdh0ia12cupsq2fqs@4ax.com> article
>Path: news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.x s4all.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.

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


I might look into trying something similar to the above, but using bash
pipes rather than with expect.

I also figured how to use "suck" to get a message by its Message-ID. This
script reads a message from a public newsserver and saves it as the file
"feedback.txt". (It also uses 3 temporary files in the local dir.)

#!/bin/bash
echo "alt.test -1 0" >sucknewsrc
echo "<0123456789abcdef@foo.invalid>" >suckothermsgs
suck aioe.cjb.net >feedback.txt
rm -f sucknewsrc suck.newrc suckothermsgs
  Réponse avec citation
Vieux 04/05/2008, 23h37   #4
Theo v. Werkhoven
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

The carbonbased lifeform Dave Farrance inspired comp.unix.shell with:
> "Theo v. Werkhoven" <theo@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@4ax.com> /* my command */
>>220 0 <l3kr14d2fhvghmla9rdh0ia12cupsq2fqs@4ax.com> article
>>Path: news.xs4all.nl!newsspool.news.xs4all.nl!newsfeed.x s4all.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@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"
  Réponse avec citation
Vieux 05/05/2008, 03h01   #5
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

In article <66vr145h4fub9ks0l6depgs62rnjlfnoar@4ax.com>,
Dave Farrance <DaveFarrance@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.

  Réponse avec citation
Vieux 05/05/2008, 04h35   #6
mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

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 checked in the
script and, message ID, can be present.
Perhaps you would prefer get a list instead, sending with the script:
se "XOVER $[$LP-5]-$LP" 224
And selecting via the "ID" as said in your post.
Try play a bit with this; add echo $REPLY >&2 to see server's answer.
I don't have examples with SSL, only this one for plain text.
I'm not sure if this is what you wanted.

------------------
#!/bin/bash

S=194.177.96.26 # nntp.aioe.org
P=119
G=comp.unix.shell

e(){ exec 3<&-;exit 1;}

se(){ # send $1 expect $2
[ -n "$1" ]&&printf "$1\r\n" >&3
read<&3;[ "${REPLY%% *}" = "$2" ]||e
}

exec 3<>/dev/tcp/$S/$P||e

se '' 200

se "MODE READER" 200

se "GROUP $G" 211
LP=${REPLY% *};LP=${LP##* } # LP = latest post

[ -f /tmp/$G ]&&LL=$[`cat /tmp/$G`+1]||LL=$LP # LL = latest local
echo -e "LL=$LL\nLP=$LP" >&2

while [ $LP -ge $LL ];do
se "ARTICLE $LL" 220
[ -e /tmp/$G.$LL ]||while read -t 3;do [ "$REPLY" = .$'\r' ]&&break
echo "$REPLY"
#echo "${REPLY%?}" # \x0d cut
done <&3 >/tmp/$G.$LL
echo /tmp/$G.$LL >&2
echo $LL >/tmp/$G
LL=$[$LL+1]
done
e
--------------------



On Sun, 04 May 2008 10:37:18 -0300, Dave Farrance
<DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> wrote:

> Below is a script that posts a test message via a public newserver and
> provides a randomly generated title and Message-ID. It uses the "rpost"
> command, which is included in the "suck" package to post the message.
>
> I'd like to add a "suck" command to the script to read the message back
> from the server, using the specified Message-ID, and to display that
> message. I guess I'll figure out how to do it eventually, but the "suck"
> command seems to be far more complex than "rpost" and it requires config
> files. There's no easy way to do this that I'm missing, is there?
>
>
> #!/bin/bash
> newsserver=aioe.cjb.net
> id=$(od -xvAn -N8 < /dev/urandom | tr -cd 0-9a-f)
> rpost $newsserver <<%end
> From: scriptpost <script@post.invalid>
> Newsgroups: alt.test
> Subject: TEST-$id
> Organization: scriptpost
> Message-ID: <$id@post.invalid>
>
> test $id
> %end


  Réponse avec citation
Vieux 05/05/2008, 04h41   #7
mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

The script works fine for this server/group!

On Mon, 05 May 2008 00:35:24 -0300, mo <invalid@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.

  Réponse avec citation
Vieux 05/05/2008, 05h34   #8
mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

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@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@k7>
References: <egdr149mrt38s127jp8aq6ufu4h7j3pjg7@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@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@post.invalid>
>
> test $id
> %end





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

> The script works fine for this server/group!
>
> On Mon, 05 May 2008 00:35:24 -0300, mo <invalid@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.


  Réponse avec citation
Vieux 05/05/2008, 18h25   #9
Dan Stromberg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

On Mon, 05 May 2008 02:01:58 +0000, Kenny McCormack wrote:

> In article <66vr145h4fub9ks0l6depgs62rnjlfnoar@4ax.com>, Dave Farrance
> <DaveFarrance@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.

  Réponse avec citation
Vieux 05/05/2008, 20h11   #10
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

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
  Réponse avec citation
Vieux 05/05/2008, 20h59   #11
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

2008-05-5, 00:37(+02), Theo v. Werkhoven:
[...]
> #v+
> !/usr/bin/expect --


ITYM

#! /usr/bin/expect --

> spawn telnet [lindex $argv 0 ] 119
> expect -re "200(.*)$"


That's a common mistake with expect. "200(.*)$" will match
anything from the first "200" until the end of the current
buffer (what's been read so far from the spawned command), not
to an end-of-line.

Also, you don't do anything in case of timeout, so you might as
well expect any return code.

If you really want to check the return code, you may want to
check that 200 appears at the start of the buffer as well, in
cases of "502 more than 1200 users logged in".

You may want to accept a code of "201" as you don't intend to
post.

If you want to do things properly, you'll soon realise that you
are actually rewriting a NNTP client, so best would be to use an
existing one or some NNTP module in some scripting language.

> send "body [lindex $argv 1]\r"
> expect -timeout 1 -re "^\.$"


Same problem as above. The end pattern to look for is
"\r\n.\r\n", Here, you're expecting the first read from the
command to return only "." which is very unlikely.

--
Stéphane
  Réponse avec citation
Vieux 05/05/2008, 21h57   #12
Dave Farrance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

mo <invalid@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.


Thanks for that. I spent a while ploughing through the Advanced Bash
Scripting Guide until I understood it that script. There were techniques
in it that were certainly worth knowing about, although I'd already
worked out how to get a specific article using suck, as I'd shown in a
previous post. Anyway, using the bash technique, getting a specific
article can be boiled down to this working minimal script:


#!/bin/bash
ip=$(getent hosts nntp.aioe.org)
exec 3<>/dev/tcp/${ip%% *}/119
read -t 3 <&3
printf "article <987654321@foo.invalid>\r\n" >&3
while read -t 1 ;do echo "$REPLY"; done <&3
exec 3<&-


--
Dave Farrance

  Réponse avec citation
Vieux 05/05/2008, 22h01   #13
Theo v. Werkhoven
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

The carbonbased lifeform Stephane CHAZELAS inspired comp.unix.shell with:
> 2008-05-5, 00:37(+02), Theo v. Werkhoven:
> [...]
>> #v+
>> !/usr/bin/expect --

>
> ITYM
>
> #! /usr/bin/expect --


I did.
Thanks for the explanations and hints. I find expect a good tool, but
it's not something I use on a daily base (as you could easily guess from
my post).

> If you want to do things properly, you'll soon realise that you
> are actually rewriting a NNTP client, so best would be to use an
> existing one or some NNTP module in some scripting language.


For anything more complicated, you're probably right.

>> send "body [lindex $argv 1]\r"
>> expect -timeout 1 -re "^\.$"

>
> Same problem as above. The end pattern to look for is
> "\r\n.\r\n", Here, you're expecting the first read from the
> command to return only "." which is very unlikely.


Cheers, I struggled for a while on that one, I couldn't figure out why
it would timeout before recognizing the '.'.

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"
  Réponse avec citation
Vieux 06/05/2008, 00h19   #14
mo
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Usenet server test script

Dave Farrance wrote:
> previous post. Anyway, using the bash technique, getting a specific
> article can be boiled down to this working minimal script:


> ip=$(getent hosts nntp.aioe.org)
> exec 3<>/dev/tcp/${ip%% *}/119


Yes,
and more, probably bash can handle directly the host name, if wanted:

$ {
exec 3<>/dev/tcp/nntp.aioe.org/119
read -t1 <&3
printf "article <987654321@foo.invalid>\r\n" >&3
Y=;while read -r -t1 R;do
case "${R%?}" in '')Y=1;;.)Y=;;*)[ $Y ]&&echo "$R";esac
done<&3
exec 3<&-
}
testing testing testing
$
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h01.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28012 seconds with 22 queries