1#!/bin/sh 2# 3# $OpenBSD: follow-newsyslog.sh,v 1.2 2012/11/03 08:41:25 ajacoutot Exp $ 4 5# test if tail follows a file rotated by newsyslog 6 7#set TMPDIR to a nfs-based dir for nfs testing 8DIR=$(mktemp -d) 9echo DIR=${DIR} 10 11NAME=${0##*/} 12OUT=${DIR}/${NAME%%.sh}.out 13ERR=${DIR}/${NAME%%.sh}.err 14echo bar > ${DIR}/bar 15 16# retry until file appears for nfs 17RET=1 18while [ ${RET} == 1 ] ; do 19 tail -f ${DIR}/bar 2> ${ERR} > ${OUT} & 20 RET=$? 21 PID=$! 22 sleep 1 23done 24 25echo "${DIR}/bar 644 1 1 *" > ${DIR}/newsyslog.conf 26newsyslog -Ff ${DIR}/newsyslog.conf 27echo 'bar' >> ${DIR}/bar 28sleep 1 29echo "${DIR}/bar 644 0 1 *" > ${DIR}/newsyslog.conf 30newsyslog -Ff ${DIR}/newsyslog.conf 31echo 'bar' >> ${DIR}/bar 32 33# hey nfs ! 34sleep 5 35kill ${PID} 36# no diff this time, output too complex 37[ $(grep -c -e '^bar$' ${OUT}) -eq 3 ] || exit 1 38[ $(grep -c -e 'newsyslog\[.*\]: logfile turned over' ${OUT}) -eq 4 ] || exit 2 39tail -1 ${OUT} | grep -q -e '^bar$' || exit 3 40head -1 ${OUT} | grep -q -e '^bar$' || exit 4 41 42#[ $(grep -c "tail: ${DIR}/bar has been truncated, resetting." ${ERR}) -eq 2 ] || exit $? 43[ $(grep -c "tail: ${DIR}/bar has been replaced, reopening." ${ERR}) -eq 2 ] || exit 5 44 45# cleanup if okay 46rm -Rf ${DIR} 47