|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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" |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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" |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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" |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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 $ |
|
![]() |
| Outils de la discussion | |
|
|