add gzip.py - RHEL6 version is too old
[compresslog.git] / ztail
blob946909a284acfbb9a36be470e7d8a9ad19df8c10
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
28 ## setup trigger flush in a background loop
29 ( sleep 1 # give time for the tailing to get started
30 err=0
31 while true ; do
32 killall -s SIGUSR1 compresslog 2>/dev/null
33 if [ $? -ne 0 ]; then
34 if [ $err -eq 0]; then
35 echo "WARNING - ztail: compresslog is not running" >&2
36 echo "WARNING - ztail: or we are not root." >&2
37 err=1
40 sleep 1
41 done ) &
42 FLUSHTRIGGERD=$!
43 trap "kill $FLUSHTRIGGERD" SIGHUP SIGINT SIGTERM
45 $mydir/zcatfollow -n $taillines $logfile
47 kill $FLUSHTRIGGERD 2>/dev/null