watchlog: skip "zero" logentries to save SQLite traffic
[compresslog.git] / ztail
blob24c512ebb9f6732cab0a11fb208c524692e414d2
1 #!/bin/bash
2 # Usage : ztail [ -n 10 ] /var/log/foo
4 # Implements ztail -f /var/log/foo
6 # License: GPLv2
7 # Author: Martin Langhoff <martin.langhoff@gmail.com>
8 # Copyright: Remote Learner US - http://www.remote-learner.net/
10 mydir=$(dirname "${BASH_SOURCE[0]}")
12 taillines=10
14 while : ; do
15 case "$1" in
16 -n)
17 taillines=$2
18 shift; shift ;;
20 break ;;
21 esac
22 done
23 logfile=$1
25 # flush before we get underway
26 killall -s SIGUSR1 compresslog 2>/dev/null
27 if [ $? -ne 0 ]; then
28 echo "WARNING - ztail: compresslog is not running" >&2
29 echo "WARNING - ztail: or we are not root." >&2
32 ## setup trigger flush in a background loop
33 ( sleep 1 # give time for the tailing to get started
34 err=0
35 while true ; do
36 killall -s SIGUSR1 compresslog 2>/dev/null
37 sleep 1
38 done ) &
39 FLUSHTRIGGERD=$!
40 trap "kill $FLUSHTRIGGERD" SIGHUP SIGINT SIGTERM
42 $mydir/zcatfollow -n $taillines $logfile
44 kill $FLUSHTRIGGERD 2>/dev/null