2 # fixscript will replace this line with require innshellvars.pl
4 # Author: James Brister <brister@vix.com> -- berkeley-unix --
5 # Start Date: Thu May 16 10:32:02 1996 +0200
6 # Project: INN -- innfeed
8 # RCSId: $Id: procbatch.in 6648 2004-01-25 20:07:11Z rra $
10 # Description: Take a file of the form generated by innd in the out.going
11 # directory ("Wnm*") and separate it into tape files for inn.
13 # Thanks to Clayton O'Neill <coneill@premier.net> for serious speed
18 # Hmm, perhaps we should try to read "backlog-directory"
19 # from innfeed.conf. Oh well.
21 $tapeDir = $inn'pathspool . "/innfeed"; #'
22 $destDir = $inn'spooltemp ; #'
23 $spoolArts = $inn'patharticles ; #'
24 $outGoing = $inn'pathoutgoing; #'
27 ## Everything below here should probably be left alone.
32 require 'getopts.pl' ;
34 $usage = "$0 [ -q ][ -v ][ -u ][ -e host ][ -d dir ][ -c [ -s dir ]][ -m [-t dir ]] inn-batchfile\n
35 -e host to process on entries for only that host
36 -d dir to put the output file(s) in that directory ($destDir)
37 -c to check pathnames of articles before storing them
38 -s dir to specify where the news articles are
40 -m to have $0 move the new files to the backlog directory.
41 -t dir to specify the backlog directory ($tapeDir)
42 -u to unlink the input files when finished
44 -q quiet mode; only display error messages. Good for cron jobs.
46 $0 will take an inn funnel file (normally a file in
47 $outGoing), or an innfeed ``dropped'' file,
48 which is presumed to be of the format:
50 pathname message-id peer1 peer2 peer3 ...
52 and will break it up into files peer1.tmp peer2.tmp peer3.tmp... Each of
53 these files wil be of the format:
57 that is the same as innfeed's backlog file format. Simply rename these files
58 to peer1 peer2 peer3 in a running innfeed's backlog directory and they will be
59 picked up automatically and processed by innfeed. Use the '-m' flag and
60 they'll be moved automatically.
63 $opt_u = $opt_h = ""; # shut up, perl -w
64 &Getopts ("he:t:s:d:cvumq") || die $usage ;
66 die $usage if ( $opt_h ) ;
67 die "Cannot specify both -q and -v\n\n" . $usage if ($opt_q && $opt_v);
69 $spoolArts = $opt_s if $opt_s ;
70 $destDir = $opt_d if $opt_d ;
71 $tapeDir = $opt_t if $opt_t ;
74 die $usage if !$inputFile ;
75 unless (-f $inputFile) {
77 die "No such file: $inputFile\n\n" . $usage;
79 die "No such directory: $spoolArts\n\n" . $usage if ( ! -d $spoolArts && $opt_c ) ;
80 die "No such directory: $destDir\n\n" . $usage if ( ! -d $destDir ) ;
81 die "No such directory: $tapeDir\n\n" . $usage if ( ! -d $tapeDir && $opt_m ) ;
83 print "Using $inputFile\n" if $opt_v ;
84 open (INPUT,"<$inputFile") || die "$0: open ($inputFile): $!\n" ;
90 # Check the format of the line vigorously
91 next unless (m!^\S+/\d+ <.+@.+> \S+! || m!^@[0-9A-F]+@ <.+@.+> \S+!) ;
94 if ( ! -f "$spoolArts/$F[0]" ) {
96 print "Dropping file: $spoolArts/$F[0]\n" if $opt_v ;
101 for ($i = 2 ; $i <= $#F ; $i++) {
103 next if ($opt_e && $opt_e ne $host) ;
105 # Keep out host names with any funny characters (from
107 if ($host !~ /^[-\._0-9A-Za-z]+$/) {
108 warn "$0: bad site name ignored: \"$host\"\n";
113 print {$hosts{$host}} "$F[0] $F[1]\n";
115 $outputFile = "$destDir/$host.tmp" ;
116 print "Starting $host\n" if ($opt_v);
118 open ($hosts{$host},">>$outputFile") ||
119 die "open >>$outputFile: $!\n" ;
120 print {$hosts{$host}} "$F[0] $F[1]\n";
126 foreach $host (keys %hosts) {
127 close($hosts{$host});
128 $outputFile = "$destDir/$host.tmp" ;
129 $tmpTape = "$tapeDir/$host.tmp" ;
130 $tapeFile = "$tapeDir/$host" ;
132 if ($outputFile ne $tmpTape) {
133 $cmd = "mv $outputFile $tmpTape" ;
135 die "$0: $cmd: failed\n" unless ($? == 0) ;
138 $cmd = "cat $tmpTape |sort -u >> $tapeFile && rm -f $tmpTape" ;
140 die "$0: $cmd: failed\n" unless ($? == 0) ;
144 unlink($inputFile) if ($opt_u);
146 print "$missing articles dropped\n" if ( $opt_v && $missing > 0 ) ;