emv@ox.com (Ed Vielmetti) (01/02/91)
>Like this? (Your mileage may vary; I'm intimate only with C News on >my Sun OS 4.0.3 system. I've wrapped lines for readability.) > > % grep 1990Dec28.202628.5720@murdoch.acc.Virginia.EDU /usr/local/lib/news/history In article <1085@toaster.SFSU.EDU> eps@toaster.SFSU.EDU (Eric P. Scott) writes: Um, history files tend to be several megabytes long, and this isn't a particularly efficient way to find things. I believe C News is distributed with a "newshist" program for fast lookups. B News sites needing similar functionality can FTP the shar file pub/newshist from sutro.sfsu.edu [130.212.15.230]. NNTP sites can already access articles directly by Message-ID. If you are on an NNTP-only site this little bit of perl might help; given a message-id, it fetches the article from any arbitrary NNTP site that allows such access and sends it to standard output. --Ed emv@ox.com #!/usr/local/bin/perl # sendme -- fetch usenet articles by Message-ID. # usage -- # sendme 1234@host.domain.org # sendme "<1234@host.domain.org>" # sendme 1234@host.domain.org nntpserver.domain.org # sendme "<1234@host.domain.org>" nntpserver.domain.org # it should do the following: # cope with B and C formats in dbm or flat file format # cope with NNTP to the default server # cope with NNTP to any server specified, or a list to try. # but it doesn't. instead it just uses NNTP. # suggested by eci386!clewis # socket code mailed to me by cmf@obie.cis.pitt.edu (Carl M. Fongheiser) # Configuration information -- change to reflect your site. $DEFAULTSERVER='nntpserver.domain.org'; # Configure here $NNTPSERVER=$ARGV[1] ? $ARGV[1] : $DEFAULTSERVER ; # should also read dbm or grep # history file. $NEWS='/usr/spool/news/lib/news'; # news library $SPOOL='/usr/spool/news'; # news spool # $DEBUG = 1; # uh, if it don't work $art = $ARGV[0]; print $art if ($DEBUG); if ($art !~ m#^<#) { $art = "<" . $art . ">"; } print $art if ($DEBUG); if ($NNTPSERVER) { $port = 'nntp'; require 'sys/socket.ph'; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name,$aliases,$proto) = getprotobyname('tcp'); ($name,$aliases,$port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname); ($name,$aliases,$type,$len,$thataddr) = gethostbyname($NNTPSERVER); $this = pack($sockaddr, &AF_INET, 0, $thisaddr); $that = pack($sockaddr, &AF_INET, $port, $thataddr); socket(N, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(N, $this) || die "bind: $!"; connect(N, $that) || die "connect: $!"; $response = <N>; if ($response !~ /^2/) { # hunky dory print STDERR $response; exit 1; } send(N,"ARTICLE $art\r\n",0); print STDERR "ARTICLE $art\r\n" if ($DEBUG); $response = <N>; if ($response !~ /^2/) { # hunky dory print STDERR $response; exit 1; } } else { die "Don't know how to do history lookups yet." ; } while(<N>) { if ($NNTPSERVER && $_ eq ".\r\n") { last; } s/.$//; print ; } if ($NNTPSERVER) { send(N, "QUIT\r\n", 0); } close(N);
brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (01/03/91)
In article <EMV.91Jan1202420@crane.aa.ox.com> emv@ox.com (Ed Vielmetti) writes: > # sendme 1234@host.domain.org > # sendme "<1234@host.domain.org>" > # sendme 1234@host.domain.org nntpserver.domain.org > # sendme "<1234@host.domain.org>" nntpserver.domain.org [ fifty-plus lines of perl ] This twenty-line sh script does the same thing in roughly the same way: #!/bin/sh case "$1" in '<'*'>') ART="$1"; export ART ;; *) ART="<$1>"; export ART ;; esac authtcp -- "${2-nntpserver.domain.org}" nntp sh -c ' exec <&6 # read input from network read response case "$response" in 20*) echo article "$ART"^M >&6 # say what article we want read response case "$response" in 22*) awk '\''/^\..$/ { exit } { print } '\'' ;; # done! *) echo "$response" >&2 ;; # oops, article no good esac ;; *) echo "$response" >&2 ;; # oops, server not ready esac echo QUIT^M >&6 ' | sed 's/.$//' # strip CRs Note that the two ^Ms should be typed as the control character. Both scripts should actually read further and look for a sudden quit by the server, but that never happens in practice. authtcp was published in comp.sources.unix volume 22. ---Dan