🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #70052

Re: NNTP server test script

#70052
From: Conrad J. Sabatier
Date: Sun, 03 Oct 2004 00:27
111 lines
3902 bytes
In article <Ajn7d.520$UP1.292@newsread1.news.pas.earthlink.net>,
Alan Connor  <xxxx@yyy.zzz> wrote:
>
>
>On Sat, 02 Oct 2004 00:49:26 GMT, Conrad J. Sabatier
><conrads@cox.net> wrote:
>
>> In article <2Sm7d.12534$Hz.12393@fed1read04>, Conrad
>> J. Sabatier <conrads@cox.net> wrote:
>>
>>
>>>In article <hTJRc.8593$_C6.863@cyclops.nntpserver.com>, John
>>>Kenickney <spam.trap@bigfoot.com> wrote:
>
><snip>
>
>> One small potential problem, I just realized, with the above
>> statement.  This will loop forever if the server returns a
>> "201" (no posting allowed) instead of "200" (posting allowed).
>>
>> Modify accordingly.
>>
>> Still, pretty amazing what you can do with a relatively simple
>> little bash script, isn't it? :-)
>>
>
>Nice job. I've been using telnet and thinking about writing a
>netcat script like yours. I'll use it as a template. Thanks.

You're welcome, and thank you.  :-)

I've included a new, improved version of the script below, which will 
handle both possible server "greetings" properly, as well as provide a 
little more in the way of feedback, by echoing all of the server's responses 
to stderr:

#!/usr/local/bin/bash
#
# usage: post article server
#
# where "article" is the filename of the article to be posted
#
# should contain, at a minimum, Newsgroups:, Subject: and From: header lines,
# followed by at least one blank line, followed by article body
#
# no "CRLF.CRLF needed at end of article; the script takes care of that
#
# "server" is, of course, the address of the server to post to
#
# server's replies are echoed to stderr
#
# exits with 0 on success, 1 on error or posting not allowed

article=$1
server=$2

# avoid any line-splitting of server's replies
IFS=""

# loop until a connection is established
while true
do
	exec < /dev/tcp/${server}/nntp && read -r &&
		[ "${REPLY%% *}" == "200" -o "${REPLY%% *}" == "201" ] &&
		echo -E $REPLY >&2 && break
done

# quit if posting not allowed
if [ "${REPLY%% *}" == "201" ]
then
	echo -e "quit\r" >&0
	read -r
	echo -E $REPLY >&2
	exit 1
fi

# send post command, check server's reply
echo -e "post\r" >&0
read -r
echo -E $REPLY >&2
if [ "${REPLY%% *}" != "340" ]
then
	echo -e "quit\r" >&0
	read -r
	echo -E $REPLY >&2
	exit 1
fi

# send the article
cat $article >&0
echo -e "\r\n.\r" >&0

# check the server's reply
read -r
echo -E $REPLY >&2
if [ "${REPLY%% *}" != "240" ]
then
	echo -e "quit\r" >&0
	read -r
	echo -E $REPLY >&2
	exit 1
fi

# do a clean exit
echo -e "quit\r" >&0
read -r
echo -E $REPLY >&2
exit 0

-- 
Conrad J. Sabatier <conrads@cox.net> -- "In Unix veritas"
Technical Details
Message-ID: <eIH7d.28050$Ok.26399@okepread04>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!gnilink.net!chi1.usenetserver.com!atl-c02.usenetserver.com!news.usenetserver.com!peer01.cox.net!cox.net!p01!okepread04.POSTED!53ab2750!not-for-mail
References: <hTJRc.8593$_C6.863@cyclops.nntpserver.com> <2Sm7d.12534$Hz.12393@fed1read04> <qWm7d.12536$Hz.9114@fed1read04> <Ajn7d.520$UP1.292@newsread1.news.pas.earthlink.net>

Show Full Headers
Complete Article Headers
Message-ID: <eIH7d.28050$Ok.26399@okepread04>
Subject: Re: NNTP server test script
Date: Sun, 03 Oct 2004 00:27:54 GMT
From: conrads@cox.net (Conrad J. Sabatier)
References: <hTJRc.8593$_C6.863@cyclops.nntpserver.com> <2Sm7d.12534$Hz.12393@fed1read04> <qWm7d.12536$Hz.9114@fed1read04> <Ajn7d.520$UP1.292@newsread1.news.pas.earthlink.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!gnilink.net!chi1.usenetserver.com!atl-c02.usenetserver.com!news.usenetserver.com!peer01.cox.net!cox.net!p01!okepread04.POSTED!53ab2750!not-for-mail
Newsgroups: news.software.nntp
X-Newsreader: trn 4.0-test76 (Apr 2, 2001)
Originator: conrads@cox.net (Conrad J. Sabatier)
Lines: 111
NNTP-Posting-Host: 68.11.71.51
X-Complaints-To: abuse@cox.net
X-Trace: okepread04 1096763274 68.11.71.51 (Sat, 02 Oct 2004 20:27:54 EDT)
NNTP-Posting-Date: Sat, 02 Oct 2004 20:27:54 EDT
Organization: Cox Communications