2 # fixscript will replace this line with code to load innshellvars
5 ## Summarize INN log files.
7 ## norotate Do not rotate logfiles
9 ## If you get an error from this line:
10 ## sh -c 'egrep "`ls /etc`" /dev/null'
11 ## then get a better egrep, like the FSF one.
13 ## Directory where old log files are kept.
15 ## If you want to archive the active file, enable this line.
17 ## Number of lines of error in each category to report.
22 ## Where these programs, if used, write their logs.
23 ## We also have to find innfeed's log file.
24 INNFEEDLOG=`${AWK} '{gsub(/:|#/, " & ")} {if ($1 == "log-file" && $2 == ":") print $3}' ${PATHETC}/innfeed.conf`
26 for F in "${INNFEEDLOG}" ; do
27 test -f "${MOST_LOGS}/${F}" && INNFEED="${INNFEED} ${MOST_LOGS}/${F}"
29 test -z "${INNFEED}" && test -f ${MOST_LOGS}/innfeed.log && INNFEED="${MOST_LOGS}/innfeed.log"
32 ## Where nntpsend, if used, writes its log information.
33 NNTPSEND=${MOST_LOGS}/nntpsend.log
34 SENDNNTP=${MOST_LOGS}/send-nntp.log
35 SENDUUCP=${MOST_LOGS}/send-uucp.log
36 LIVEFILES="${INNFEED} ${NNTPSEND} ${SENDNNTP} ${SENDUUCP}"
37 ## Where news.daily places expire output, unless noexplog was used.
38 EXPLOG=${MOST_LOGS}/expire.log
40 ## If you divide your news syslog into separate files, list them here.
41 SYSLOG_CRIT=${MOST_LOGS}/news.crit
42 SYSLOG_ERR=${MOST_LOGS}/news.err
43 SYSLOG_NOTICE=${MOST_LOGS}/news.notice
44 SYSLOGS="${SYSLOG_CRIT} ${SYSLOG_ERR} ${SYSLOG_NOTICE}"
46 ## Where tally control and unwanted processors are found.
47 TALLY_CONTROL=${PATHBIN}/tally.control
48 TALLY_UNWANTED=${PATHBIN}/tally.unwanted
49 UNWANTED_LOG=${MOST_LOGS}/unwanted.log
50 CONTROL_LOG=${MOST_LOGS}/control.log
52 test -f ${MOST_LOGS}/newgroup.log && CONTROL_DATA=${MOST_LOGS}/newgroup.log
53 test -f ${MOST_LOGS}/rmgroup.log \
54 && CONTROL_DATA="${CONTROL_DATA} ${MOST_LOGS}/rmgroup.log"
56 ## Build up the list of log files to process.
57 LOGS="${ERRLOG} ${EXPLOG} ${LOG} ${ACTIVEFILE} ${SYSLOGS} ${UNWANTED_LOG}"
59 for F in ${LIVEFILES} ; do
60 test -n "${F}" -a -f "${F}" && LOGS="${LOGS} ${F}"
63 test -n "${CONTROL_DATA}" && LOGS="${LOGS} ${CONTROL_LOG}"
64 for F in checkgroups default ihave newgroup rmgroup sendme sendsys \
65 senduuname version miscctl badcontrol failedpgp badpgp; do
66 test -f ${MOST_LOGS}/${F}.log && LOGS="${LOGS} ${MOST_LOGS}/${F}.log"
70 LOCK=${LOCKS}/LOCK.${PROGNAME}
86 echo "Unknown flag ${I}" 1>&2
92 ## Make sure every log exists.
94 test ! -f ${F} && touch ${F}
99 PROBS=${TMPDIR}/scanlog$$
100 trap "rm -f ${T} ${PROBS}; exit 0" 0 1 2 3 15
105 shlock -p $$ -f ${LOCK} || {
106 echo "$0: Locked by `cat ${LOCK}`"
109 trap "rm -f ${T} ${PROBS} ${LOCK}; exit 0" 1 2 3 15
113 test ! -d ${OLD} && mkdir ${OLD}
117 ctlinnd -s pause "Flushing log and syslog files" 2>&1 && PAUSED=true
118 OUTPUT=`ctlinnd flushlogs 2>&1`
119 if [ "$OUTPUT" != "Ok" -a "$OUTPUT" != "In debug mode" ]; then
121 echo 'Cannot flush logs.'
126 ## Make sure these .old files exist, in case innd is down.
127 for F in ${LOG} ${ERRLOG} ${EXPLOG} ; do
128 if [ ! -f ${F}.old ]; then
135 ## Copy syslog files, truncating old inode since syslog has it open.
136 for F in ${SYSLOGS}; do
143 ## Make a copy of the active file.
144 if [ -n ${ACTIVEFILE} ] ; then
145 BASE=`basename ${ACTIVEFILE}`
146 rm -f ${OLD}/${BASE}.old
147 cp ${ACTIVEFILE} ${OLD}/${BASE}.old
150 ## These are live files, so use link rather than copy.
151 for F in ${LIVEFILES} ; do
153 rm -f ${F}.old ${F}.new
161 ## Tally control messages if we logged them.
162 test -n "${CONTROL_DATA}" && cat ${CONTROL_DATA} | ${TALLY_CONTROL}
164 ${PAUSED} && ctlinnd -s go "Flushing log and syslog files" 2>&1
168 ## Process the current (just-flushed) log
172 ${SYSLOG_CRIT}|${ERRLOG}|${EXPLOG}|${LOG}|${SYSLOG_NOTICE})
173 ## Make a link that can be deleted (since if not rotating
174 ## we delete the copy that is made in ${TMPDIR}).
175 mv ${F}.old ${OLD}/${BASE}
176 rm -f ${OLD}/${BASE}.0
177 ln ${OLD}/${BASE} ${OLD}/${BASE}.0
180 mv ${BASE}.old ${OLD}/${BASE}
183 mv ${F}.old ${OLD}/${BASE}
186 ## Rotate and compress the file.
188 if [ ! -f ${BASE} -a -f ../${BASE} ]; then
189 cp ../${BASE} ${BASE}
192 if [ -f ${BASE} ]; then
193 ${LOG_COMPRESS} <${BASE} >${BASE}.0${Z} && rm -f ${BASE}
194 chmod 0440 ${BASE}.0${Z}
197 if [ X${LOGCYCLES} = X ]; then
201 rm -f ${BASE}.${LOGCYCLES}${Z}
202 while [ ${EXT} -gt 0 ] ; do
204 EXT=`expr ${EXT} - 1`
205 test -f ${BASE}.${EXT}${Z} \
206 && rm -f ${BASE}.${NEXT}${Z} \
207 && mv ${BASE}.${EXT}${Z} ${BASE}.${NEXT}${Z}
210 ## Innreport assumes where unwanted.log exists, so leave it
211 ## and process later.
214 if [ -f ${F}.old ]; then
215 mv ${F}.old ${OLD}/${BASE}
217 rm -f ${OLD}/${BASE} ${F}.new
222 mv ${F}.old ${OLD}/${BASE}
229 ## Don't use the real OLD directory, instead use TMPDIR
232 ## Make a snapshot of what we need for below.
233 ctlinnd -s pause "Snapshot log and syslog files" 2>&1
234 for F in ${SYSLOG_CRIT} ${ERRLOG} ${EXPLOG} ${LOG} ${SYSLOG_NOTICE} ; do
236 rm -f ${OLD}/${BASE}.0
237 cp ${F} ${OLD}/${BASE}.0
239 ctlinnd -s go "Snapshot log and syslog files" 2>&1
243 ## We now (finally!) have copies of the log files where we need them.
246 ## Display syslog critical messages.
247 BASE=`basename ${SYSLOG_CRIT}`
248 OLD_SYSLOG=${OLD}/${BASE}.0
249 if [ -s ${OLD_SYSLOG} ] ; then
250 echo Syslog critical messages:
257 ## Display error log.
258 BASE=`basename ${ERRLOG}`
259 OLD_ERRLOG=${OLD}/${BASE}.0
260 if [ -s ${OLD_ERRLOG} ] ; then
268 ## Scan for various problems in articles we were offered or sent...
269 BASE=`basename ${LOG}`
270 OLD_LOG=${OLD}/${BASE}.0
272 ## and summarize syslog information.
273 BASE=`basename ${SYSLOG_NOTICE}`
274 OLD_SYSLOG=${OLD}/${BASE}.0
275 if [ -s ${OLD_SYSLOG} -o -s ${OLD_LOG} ] ; then
276 ${PATHBIN}/innreport -f ${PATHETC}/innreport.conf ${OLD_SYSLOG} ${OLD_LOG}
280 rm -f ${OLD_LOG} ${OLD_SYSLOG}
282 BASE=`basename ${UNWANTED_LOG}`
283 if [ -f ${UNWANTED_LOG}.old ]; then
284 mv ${UNWANTED_LOG}.old ${OLD}/${BASE}
287 cp ${UNWANTED_LOG} ${OLD}/${BASE}
288 chmod 0660 ${OLD}/${BASE}
292 OLD_SYSLOG=${OLD}/${EXPLOG}.0
295 ## Compress and rotate the logs.
298 if [ X${LOGCYCLES} = X ]; then
301 for F in ${LOGS} ; do
302 ## Skip if it's unwanted.log, since it's already rotated
303 if [ ${F} = ${UNWANTED_LOG} ]; then
306 ## Skip if file doesn't exist.
308 test -f ${BASE} || continue
310 ## Compress the file.
311 ${LOG_COMPRESS} <${BASE} >${BASE}.0${Z} && rm -f ${BASE}
312 chmod 0440 ${BASE}.0${Z}
316 rm -f ${BASE}.${LOGCYCLES}${Z}
317 while [ ${EXT} -gt 0 ] ; do
319 EXT=`expr ${EXT} - 1`
320 test -f ${BASE}.${EXT}${Z} \
321 && rm -f ${BASE}.${NEXT}${Z} \
322 && mv ${BASE}.${EXT}${Z} ${BASE}.${NEXT}${Z}