|
Prev: Brand Watches Tissot Men's T Race Chronograph Watch #T90.4.446.51 Discount, Swiss, Fake
Next: ssh timeout script
From: Stephane CHAZELAS on 5 May 2008 15:59 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
From: Dave Farrance on 5 May 2008 16:57 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. 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(a)foo.invalid>\r\n" >&3 while read -t 1 ;do echo "$REPLY"; done <&3 exec 3<&- -- Dave Farrance
From: Theo v. Werkhoven on 5 May 2008 17:01 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"
From: mo on 5 May 2008 19:19 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(a)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 $
First
|
Prev
|
Pages: 1 2 3 Prev: Brand Watches Tissot Men's T Race Chronograph Watch #T90.4.446.51 Discount, Swiss, Fake Next: ssh timeout script |