5 # A regular expression matching the format of an RFC-5424 log line header,
6 # including the timestamp up through the seconds indicator; it does not include
7 # the (optional) timezone offset.
8 RFC5424_FMT='^<[0-9][0-9]*>1 [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}'
10 # A regular expression matching the format of an RFC-3164 (traditional syslog)
11 # log line header, including the timestamp.
12 RFC3164_FMT='^[A-Z][a-z]{2} [ 0-9][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}'
17 echo "$0: Can't create temp dir, exiting..."
21 # Begin an individual test
24 COUNT=`expr $COUNT + 1`
29 # End an individual test
41 # Make a file that can later be verified
48 # Verify that the file specified is correct
51 if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null
59 # Check that a file exists
70 # Verify that the specified file does not exist
82 # Check if a file is there, depending of if it's supposed to or not -
83 # basically how many log files we are supposed to keep vs. how many we
91 if [ $curcnt -le $keepcnt ]
93 #echo Assuming file there
96 #echo Assuming file NOT there
101 # Verify that the specified file has RFC-5424 rotation messages.
104 local lc=$(wc -l $1 | cut -w -f2)
105 local rc=$(grep -cE "${RFC5424_FMT}" $1)
106 if [ "$lc" -eq 0 -o "$rc" -eq 0 -o "$lc" -ne "$rc" ]
115 # Verify that the specified file has RFC-3164 rotation messages.
118 local lc=$(wc -l $1 | cut -w -f2)
119 local rc=$(grep -cE "${RFC3164_FMT}" $1)
120 if [ "$lc" -eq 0 -o "$rc" -eq 0 -o "$lc" -ne "$rc" ]
129 # A part of a test succeeds
135 # A part of a test fails
141 # Verify that the exit code passed is for unsuccessful termination
152 # Verify that the exit code passed is for successful termination
163 # Check that there are X files which match expr
167 if [ $cnt -eq `echo "$@" | wc -w` ]
175 # Check that two strings are alike
188 mkdir -p ${TMPDIR}/log ${TMPDIR}/alog
195 rm -rf "${TMPDIR}/log" "${TMPDIR}/alog" newsyslog.conf
201 newsyslog -f ../newsyslog.conf -F -r "$@"
204 tests_normal_rotate() {
208 if [ -n "$dir" ]; then
209 newsyslog_args=" -a ${dir}"
210 name_postfix="${ext} archive dir"
213 name_postfix="${ext}"
218 begin "create file ${name_postfix}" -newdir
221 cknt ${dir}${LOGFNAME}.0${ext}
224 begin "rotate normal 1 ${name_postfix}"
225 run_newsyslog $newsyslog_args
227 ckfe ${dir}${LOGFNAME}.0${ext}
228 cknt ${dir}${LOGFNAME}.1${ext}
231 begin "rotate normal 2 ${name_postfix}"
232 run_newsyslog $newsyslog_args
234 ckfe ${dir}${LOGFNAME}.0${ext}
235 ckfe ${dir}${LOGFNAME}.1${ext}
236 cknt ${dir}${LOGFNAME}.2${ext}
239 begin "rotate normal 3 ${name_postfix}"
240 run_newsyslog $newsyslog_args
242 ckfe ${dir}${LOGFNAME}.0${ext}
243 ckfe ${dir}${LOGFNAME}.1${ext}
244 ckfe ${dir}${LOGFNAME}.2${ext}
245 cknt ${dir}${LOGFNAME}.3${ext}
248 begin "rotate normal 4 ${name_postfix}"
249 run_newsyslog $newsyslog_args
251 ckfe ${dir}${LOGFNAME}.0${ext}
252 ckfe ${dir}${LOGFNAME}.1${ext}
253 ckfe ${dir}${LOGFNAME}.2${ext}
254 cknt ${dir}${LOGFNAME}.4${ext}
257 begin "rotate normal 5 ${name_postfix}"
258 run_newsyslog $newsyslog_args
260 ckfe ${dir}${LOGFNAME}.0${ext}
261 ckfe ${dir}${LOGFNAME}.1${ext}
262 ckfe ${dir}${LOGFNAME}.2${ext}
263 cknt ${dir}${LOGFNAME}.4${ext}
266 # Wait a bit so we can see if the noaction test rotates files
269 begin "noaction ${name_postfix}"
270 ofiles=`ls -Tl ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
271 run_newsyslog ${newsyslog_args} -n >/dev/null
273 ckstr "$ofiles" "`ls -lT ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
279 tests_normal_rotate_keepn() {
284 if [ -n "$dir" ]; then
285 newsyslog_args=" -a ${dir}"
286 name_postfix="${ext} archive dir"
289 name_postfix="${ext}"
294 begin "create file ${name_postfix}" -newdir
297 cknt ${dir}${LOGFNAME}.0${ext}
300 begin "rotate normal 1 cnt=$cnt ${name_postfix}"
301 run_newsyslog $newsyslog_args
303 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
304 cknt ${dir}${LOGFNAME}.1${ext}
307 begin "rotate normal 2 cnt=$cnt ${name_postfix}"
308 run_newsyslog $newsyslog_args
310 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
311 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
312 cknt ${dir}${LOGFNAME}.2${ext}
315 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
316 run_newsyslog $newsyslog_args
318 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
319 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
320 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
321 cknt ${dir}${LOGFNAME}.3${ext}
324 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
325 run_newsyslog $newsyslog_args
327 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
328 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
329 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
330 ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext}
331 cknt ${dir}${LOGFNAME}.4${ext}
334 # Wait a bit so we can see if the noaction test rotates files
337 begin "noaction ${name_postfix}"
338 osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'`
339 run_newsyslog ${newsyslog_args} -n >/dev/null
341 ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`"
347 tests_time_rotate() {
351 if [ -n "$dir" ]; then
352 newsyslog_args="-t DEFAULT -a ${dir}"
353 name_postfix="${ext} archive dir"
355 newsyslog_args="-t DEFAULT"
356 name_postfix="${ext}"
361 begin "create file ${name_postfix}" -newdir
362 run_newsyslog -C ${newsyslog_args}
366 begin "rotate time 1 ${name_postfix}"
367 run_newsyslog ${newsyslog_args}
369 chkfcnt 1 ${dir}${LOGFNAME}.*${ext}
374 begin "rotate time 2 ${name_postfix}"
375 run_newsyslog ${newsyslog_args}
377 chkfcnt 2 ${dir}${LOGFNAME}.*${ext}
382 begin "rotate time 3 ${name_postfix}"
383 run_newsyslog ${newsyslog_args}
385 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
390 begin "rotate time 4 ${name_postfix}"
391 run_newsyslog ${newsyslog_args}
393 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
396 begin "noaction ${name_postfix}"
397 ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
398 run_newsyslog ${newsyslog_args} -n >/dev/null
400 ckstr "$ofiles" "`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
410 if [ -n "$dir" ]; then
411 newsyslog_args=" -a ${dir}"
412 name_postfix="${ext} archive dir"
415 name_postfix="${ext}"
420 begin "RFC-5424 - create file ${name_postfix}" -newdir
423 cknt ${dir}${LOGFNAME}.0${ext}
425 cknt ${dir}${LOGFNAME5424}.0${ext}
426 ckrfc3164 ${LOGFNAME}
427 ckrfc5424 ${LOGFNAME5424}
430 begin "RFC-5424 - rotate normal 1 ${name_postfix}"
431 run_newsyslog $newsyslog_args
433 ckfe ${dir}${LOGFNAME}.0${ext}
435 ckfe ${dir}${LOGFNAME5424}.0${ext}
436 ckrfc3164 ${LOGFNAME}
437 ckrfc3164 ${dir}${LOGFNAME}.0${ext}
438 ckrfc5424 ${LOGFNAME5424}
439 ckrfc5424 ${dir}${LOGFNAME5424}.0${ext}
450 LOGFPATH=${TMPDIR}/log/${LOGFNAME}
452 # Log file for RFC-5424 testing
453 LOGFNAME5424=foo5424.log
454 LOGFPATH5424=${TMPDIR}/log/${LOGFNAME5424}
456 # Normal, no archive dir, keep X files
457 echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf
458 tests_normal_rotate_keepn 0
460 echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf
461 tests_normal_rotate_keepn 1
463 echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf
464 tests_normal_rotate_keepn 2
466 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
467 tests_normal_rotate_keepn 3
469 # Normal, no archive dir, keep X files, gz
470 echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf
471 tests_normal_rotate_keepn 0 ".gz"
473 echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf
474 tests_normal_rotate_keepn 1 ".gz"
476 echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf
477 tests_normal_rotate_keepn 2 ".gz"
479 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
480 tests_normal_rotate_keepn 3 ".gz"
482 # Normal, no archive dir
483 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
486 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
487 tests_normal_rotate ".gz"
489 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
490 tests_normal_rotate ".bz2"
492 # Normal, archive dir
493 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
494 tests_normal_rotate "" "${TMPDIR}/alog/"
496 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
497 tests_normal_rotate ".gz" "${TMPDIR}/alog/"
499 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
500 tests_normal_rotate ".bz2" "${TMPDIR}/alog/"
502 # Time based, no archive dir
503 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
506 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
507 tests_time_rotate "gz" ""
509 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
510 tests_time_rotate "bz2" ""
512 # Time based, archive dir
513 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
514 tests_time_rotate "" "${TMPDIR}/alog/"
516 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
517 tests_time_rotate "gz" "${TMPDIR}/alog/"
519 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
520 tests_time_rotate "bz2" "${TMPDIR}/alog/"
522 # RFC-5424; Normal, no archive dir
523 echo "$LOGFPATH5424 640 3 * @T00 NCT" > newsyslog.conf
524 echo "$LOGFPATH 640 3 * @T00 NC" >> newsyslog.conf