ztail now works properly, rename compresslog
[compresslog.git] / ztail
blob4fc1b970c7cfd3046265e5f6b8c8d4916a56db83
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 logfile=$1
11 mydir=$(dirname "${BASH_SOURCE[0]}")
13 # flush before we get underway
14 killall -s SIGUSR1 compresslog
16 ## setup trigger flush in a background loop
17 ( sleep 1 # give time for the tailing to get started
18 err=0
19 while true ; do
20 killall -s SIGUSR1 compresslog 2>/dev/null
21 if [ $? -ne 0 ]; then
22 if [ $err -eq 0]; then
23 echo "WARNING - ztail: compresslog is not running" >&2
24 echo "WARNING - ztail: or we are not root." >&2
25 err=1
28 sleep 1
29 done ) &
30 FLUSHTRIGGERD=$!
31 trap "kill $FLUSHTRIGGERD" SIGHUP SIGINT SIGTERM
33 $mydir/zcatfollow -n 10 $logfile
35 kill $FLUSHTRIGGERD