2 # fixscript will replace this line with code to load innshellvars
5 ## Send news via NNTP by running several innxmit processes in the background.
7 ## nntpsend [-n][-p][-r][-s size][-S][-t timeout][-T limit][host fqdn]...
8 ## -a Always have innxmit rewrite the batchfile
9 ## -d debug mode, run innxmits with debug as well
10 ## -D same as -d except innxmits are not debugged
11 ## -p Run innxmit with -p to prune batch files
12 ## -r innxmit, don't requeue on unexpected error code
13 ## -s size limit the =n file to size bytes
14 ## -c disable message-ID checking in streaming mode
15 ## -t timeout innxmit timeout to make connection (def: 180)
16 ## -T limit innxmit connection transmit time limit (def: forever)
17 ## -P portnum port number to use
18 ## -l innxmit, log rejected articles
19 ## -N innxmit, disable streaming mode
20 ## -n do not lock for nntpsend, do not sleep between sets
21 ## -w delay wait delay seconds just before innxmit
22 ## host fqdn send to host and qualified domain (def: nntpsend.ctl)
23 ## If no "host fqdn" pairs appear on the command line, then ${CTLFILE}
26 PROGNAME=`basename $0`
27 LOCK=${LOCKS}/LOCK.${PROGNAME}
28 CTLFILE=${PATHETC}/${PROGNAME}.ctl
29 LOG=${MOST_LOGS}/${PROGNAME}.log
50 while ${MORETODO} ; do
82 echo "${PROGNAME}: option requires an argument -- s" 1>&2
89 TRUNC_SIZE="`echo $1 | ${SED} -e 's/-s//'`"
93 echo "${PROGNAME}: option requires an argument -- t" 1>&2
103 if [ -z "$2" ] ; then
104 echo "${PROGNAME}: option requires an argument -- P" 1>&2
114 if [ -z "$2" ] ; then
115 echo "${PROGNAME}: option requires an argument -- T" 1>&2
128 if [ -z "$2" ] ; then
129 echo "${PROGNAME}: option requires an argument -- w" 1>&2
140 echo "${PROGNAME}: illegal option -- $1" 1>&2
150 ## grab the lock if not -n
151 NNTPLOCK=${LOCKS}/LOCK.nntpsend
152 if [ -z "${NOLOCK}" ]; then
153 shlock -p $$ -f ${NNTPLOCK} || {
159 ## Parse arguments; host/fqdn pairs.
160 INPUT=${TMPDIR}/nntpsend$$
161 cp /dev/null ${INPUT}
162 while [ $# -gt 0 ]; do
163 if [ $# -lt 2 ]; then
164 echo "${PROGNAME}: Bad host/fqdn pair" 1>&2
168 echo "$1 $2" >>${INPUT}
173 ## If nothing specified on the command line, read the control file.
174 if [ ! -s ${INPUT} ] ; then
175 if [ ! -r ${CTLFILE} ]; then
176 echo "${PROGNAME}: cannot read ${CTLFILE}"
180 ${SED} -e 's/#.*//' -e '/^$/d' -e 's/::\([^:]*\)$/:max:\1/' \
181 -e 's/:/ /g' <${CTLFILE} >${INPUT}
184 ## Go to where the action is.
185 if [ ! -d ${BATCH} ]; then
186 echo "${PROGNAME}: directory ${BATCH} not found" 1>&2
194 if [ -z "${NO_LOG_FLAG}" ]; then
195 test ! -f ${LOG} && touch ${LOG}
200 echo "${PROGNAME}: [${PARENTPID}] start"
202 ## Set up environment.
203 export BATCH PROGNAME PARENTPID INNFLAGS
205 ## Loop over all sites.
206 cat ${INPUT} | while read SITE HOST SIZE_ARG FLAGS; do
207 ## Parse the input parameters.
208 if [ -z "${SITE}" -o -z "${HOST}" ] ; then
209 echo "Ignoring bad line: ${SITE} ${HOST} ${SIZE_ARG} ${FLAGS}" 1>&2
213 ## give up early if we cannot even lock it
215 ## NOTE: This lock is not nntpsend's lock but rather the
216 ## lock that the parent shell of innxmit will use.
217 ## Later on the child will take the lock from us.
219 LOCK="${LOCKS}/LOCK.${SITE}"
220 shlock -p $$ -f "${LOCK}" || continue
222 ## Compute the specific parameters for this site.
223 test "${SIZE_ARG}" = "max" && SIZE_ARG=
224 if [ -n "${TRUNC_SIZE}" ]; then
225 SIZE_ARG="${TRUNC_SIZE}"
227 ## Parse the SIZE_ARG for either MaxSize-TruncSize or TruncSize
228 case "${SIZE_ARG}" in
229 *-*) MAXSIZE="`echo ${SIZE_ARG} | ${SED} -e 's/-.*//'`";
230 SIZE="`echo ${SIZE_ARG} | ${SED} -e 's/^.*-//'`" ;;
231 *) MAXSIZE="${SIZE_ARG}";
232 SIZE="${SIZE_ARG}" ;;
243 if [ -z "${FLAGS}" ]; then
249 while ${MORETODO} ; do
275 if [ -z "$2" ] ; then
276 echo "${PROGNAME}: option requires an argument -- t" 1>&2
277 rm -f "${NNTPLOCK}" "${LOCK}"
287 if [ -z "$2" ] ; then
288 echo "${PROGNAME}: option requires an argument -- P" 1>&2
289 rm -f "${NNTPLOCK}" "${LOCK}"
299 if [ -z "$2" ] ; then
300 echo "${PROGNAME}: option requires an argument -- T" 1>&2
301 rm -f "${NNTPLOCK}" "${LOCK}"
304 TIMELIMIT_PARAM="-T$2"
311 if [ -z "$2" ] ; then
312 echo "${PROGNAME}: option requires an argument -- w" 1>&2
313 rm -f "${NNTPLOCK}" "${LOCK}"
325 if [ -z "${SIZE}" -o -n "${A_FLAG}" ]; then
326 # rewrite batch file if we do not have a size limit
329 # we have a size limit, let shrinkfile rewrite the file
332 if [ -n "${D_FLAG}" ]; then
333 INNFLAGS="${INNFLAGS} ${D_FLAG}"
335 test -n "${D_PARAM}" && INNFLAGS="${INNFLAGS} ${D_PARAM}"
337 if [ -n "${C_FLAG}" ]; then
338 INNFLAGS="${INNFLAGS} ${C_FLAG}"
340 test -n "${C_PARAM}" && INNFLAGS="${INNFLAGS} ${C_PARAM}"
342 if [ -n "${P_FLAG}" ]; then
343 INNFLAGS="${INNFLAGS} ${P_FLAG}"
345 test -n "${P_PARAM}" && INNFLAGS="${INNFLAGS} ${P_PARAM}"
347 if [ -n "${L_FLAG}" ]; then
348 INNFLAGS="${INNFLAGS} ${L_FLAG}"
350 test -n "${L_PARAM}" && INNFLAGS="${INNFLAGS} ${L_PARAM}"
352 if [ -n "${R_FLAG}" ]; then
353 INNFLAGS="${INNFLAGS} ${R_FLAG}"
355 test -n "${R_PARAM}" && INNFLAGS="${INNFLAGS} ${R_PARAM}"
357 if [ -n "${S_FLAG}" ]; then
358 INNFLAGS="${INNFLAGS} ${S_FLAG}"
360 test -n "${S_PARAM}" && INNFLAGS="${INNFLAGS} ${S_PARAM}"
362 if [ -n "${S2_FLAG}" ]; then
363 INNFLAGS="${INNFLAGS} ${S2_FLAG}"
365 test -n "${S2_PARAM}" && INNFLAGS="${INNFLAGS} ${S2_PARAM}"
367 if [ -n "${T_FLAG}" ]; then
368 INNFLAGS="${INNFLAGS} ${T_FLAG}"
370 test -n "${TIMEOUT_PARAM}" && INNFLAGS="${INNFLAGS} ${TIMEOUT_PARAM}"
372 if [ -n "${PP_FLAG}" ]; then
373 INNFLAGS="${INNFLAGS} ${PP_FLAG}"
375 test -n "${PP_PARAM}" && INNFLAGS="${INNFLAGS} ${PP_PARAM}"
377 if [ -n "${TIMELIMIT}" ]; then
378 INNFLAGS="${INNFLAGS} ${TIMELIMIT}"
380 test -n "${TIMELIMIT_PARAM}" \
381 && INNFLAGS="${INNFLAGS} ${TIMELIMIT_PARAM}"
384 ## Flush the buffers for the site now, rather than in the child.
385 ## This helps pace the number of ctlinnd commands because the
386 ## nntpsend process does not proceed until the site flush has
389 # carry old unfinished work over to this task
390 BATCHFILE="${SITE}=n"
391 if [ -f "${SITE}.work" ] ; then
392 cat ${SITE}.work >>"${BATCHFILE}"
395 # form BATCHFILE to hold the work for this site
396 if [ -f "${SITE}" ]; then
397 mv "${SITE}" "${SITE}.work"
398 if ctlinnd -s -t30 flush ${SITE} ; then
399 cat ${SITE}.work >>"${BATCHFILE}"
402 # flush failed, continue if we have any batchfile to work on
403 echo "${PROGNAME}: bad flush for ${HOST} via ${SITE}"
404 if [ -f "${BATCHFILE}" ]; then
405 echo "${PROGNAME}: trying ${HOST} via ${SITE} anyway"
407 echo "${PROGNAME}: skipping ${HOST} via ${SITE}"
413 # nothing to work on, so flush and move on
414 ctlinnd -s -t30 flush ${SITE}
415 echo "${PROGNAME}: file ${BATCH}/${SITE} for ${HOST} not found"
416 if [ -f "${BATCHFILE}" ]; then
417 echo "${PROGNAME}: trying ${HOST} via ${SITE} anyway"
419 echo "${PROGNAME}: skipping ${HOST} via ${SITE}"
425 ## Start sending this site in the background.
426 export MAXSIZE SITE HOST PROGNAME PARENTPID SIZE TMPDIR LOCK BATCHFILE W_SECONDS
428 # grab the lock from the parent
430 # This is safe because only the parent will have locked
431 # the site. We break the lock and reclaim it.
433 trap "rm -f ${LOCK} ; exit 1" 1 2 3 15
434 shlock -p $$ -f ${LOCK} || {
436 echo "${PROGNAME}: [${PARENTPID}:$$] ${SITE} locked ${WHY} `date`"
439 # process the site BATCHFILE
440 if [ -f "${BATCHFILE}" ]; then
441 test -n "${SIZE}" && shrinkfile -m${MAXSIZE} -s${SIZE} -v ${BATCHFILE}
442 if [ -s ${BATCHFILE} ] ; then
443 if [ -n "${W_SECONDS}" ] ; then
444 echo "${PROGNAME}: [${PARENTPID}:$$] sleeping ${W_SECONDS} seconds before ${SITE}"
447 echo "${PROGNAME}: [${PARENTPID}:$$] begin ${SITE} `date`"
448 echo "${PROGNAME}: [${PARENTPID}:$$] innxmit ${INNFLAGS} ${HOST} ..."
449 eval innxmit ${INNFLAGS} ${HOST} ${BATCH}/${BATCHFILE}
450 echo "${PROGNAME}: [${PARENTPID}:$$] end ${SITE} `date`"
455 echo "${PROGNAME}: file ${BATCH}/${BATCHFILE} for ${HOST} not found"
461 ## release the nntpsend lock and clean up before we wait on child processes
462 if [ -z "${NOLOCK}" ]; then
467 ## wait for child processes to finish
471 echo "${PROGNAME}: [${PARENTPID}] stop"