Posting to Usenet

If some portion of your job requires periodic postings to Useneta FAQ listing, for examplethe following Perl program can automate the process for you. In the sample code, the posted text is read in from a text file, but your input can come from anywhere.

The program shown in Listing 27.8 uses the Net::NNTP module, which is a standard part of the Perl distribution. You can find more documentation on the Net::NNTP module by typing 'perldoc Net::NNTP' at the command line.

Listing 27.8. Posting an Article to Usenet

# load the post data into @post open (POST, "post.file"); @post = <POST>;

close POST;

# import the NNTP module use Net::NNTP; $NNTPhost = 'news';

# attempt to connect to the remote host;

# print an error message on failure $nntp = Net::NNTP->new($NNTPhost)

or die "Cannot contact $NNTPhost: $!";

# send the header of the post

$nntp->datasend("Newsgroups: news.announce\n");

$nntp->datasend("Subject: FAQ - Frequently Asked Questions\n"); $nntp->datasend("From: ADMIN <root\>\n") ; $nntp->datasend("\n\n");

# for each line in the @post array, send it for (@post) {

$nntp->datasend($_); } # End for $nntp->quit;

Was this article helpful?

0 0

Post a comment