Article View: news.software.nntp
Article #24651Re: Text file to News/NNTP posting
From: Steve Rawlinson
Date: Mon, 29 Dec 1997 00:00
Date: Mon, 29 Dec 1997 00:00
90 lines
2268 bytes
2268 bytes
>> Is there a package/perl script that will allow me to post a message to a
>> nntp host? I produce some stats on the news server that I would like to
>> auto-post to a local group.
Here's a script I use to post announcements which are piped to stdin.
You'll need to change the header strings, obviously.
steve
#!/usr/bin/perl
use Socket;
use FileHandle;
my ($remote, $port, $iaddr, $paddr, $proto, $line);
$remote = 'news.clara.net';
$port = 'nntp';
$port = getservbyname($port, 'tcp'); print "port: $port\n";
$iaddr = inet_aton($remote);
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
# read in the article
chop($date = <STDIN>);
chop($subject = <STDIN>);
@body = <STDIN>;
$lines = @body;
# construct header
$head = "From: ClaraNET Announce <announce\@clara.net>
Newsgroups: claranet.announce,claranet.systems
Followup-To: claranet.systems
Subject: $subject
Date: $date
Lines: $lines\n\n";
$article = sprintf ("$head @body\n.\n");
socket (SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
connect (SOCK, $paddr);
autoflush SOCK 1;
$sock = <SOCK>;
if ($sock =~ /^200.*posting ok/) {
# ok to continue
print "received: $sock";
print SOCK "POST\n";
$sock = <SOCK>;
print "received: $sock";
if ($sock =~ /^340 Ok/) {
print SOCK $article;
} else {
print "ERROR\n";
print SOCK "QUIT\n";
exit 1;
}
} else {
# error
print "ERROR: $sock\n";
print "QUIT\n";
}
$sock = <SOCK>;
print "received: $sock";
print SOCK "QUIT\n";
exit 0;
--
Steve Rawlinson
ClaraNet Ltd
steve@clara.net
0171 903 3000
Technical Details
Message-ID:
<34a7eb9f.536188790@eros.clara.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.mbox.zip!not-for-mailReferences:
<688jms$1lf$1@valkyrie.OnRamp.Net> <m3en2waxbs.fsf@windlord.Stanford.EDU>Show Full Headers
Complete Article Headers
Message-ID: <34a7eb9f.536188790@eros.clara.net> Subject: Re: Text file to News/NNTP posting Date: Mon, 29 Dec 1997 00:00:00 +0000 From: steve@clara.net (Steve Rawlinson) References: <688jms$1lf$1@valkyrie.OnRamp.Net> <m3en2waxbs.fsf@windlord.Stanford.EDU> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 311085443 Newsgroups: news.software.nntp