File: logwatch.sh

package info (click to toggle)
gcc-13 13.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 94,620 kB
  • sloc: makefile: 2,712; python: 1,107; sh: 955; awk: 23; perl: 18; cpp: 14
file content (125 lines) | stat: -rwxr-xr-x 2,211 bytes parent folder | download | duplicates (31)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#! /bin/bash

# script to trick the build daemons and output something, if there is
# still test/build activity

# $1: primary file to watch. if there is activity on this file, we do nothing
# $2: build dir to search for dejagnu log files
#      if the files are modified or are newly created, then the message
#      is printed on stdout.
#      if nothing is modified, don't output anything (so the buildd timeout
#      hits).

pidfile=logwatch.pid
timeout=1800
message='logwatch still running'

usage()
{
    echo >&2 "usage: `basename $0` [-p <pidfile>] [-t <timeout>] [-m <message>]"
    echo >&2 "           <primary logfile> <build dir>"
    exit 1
}

while [ $# -gt 0 ]; do
    case $1 in
    -p)
	pidfile=$2
	shift
	shift
	;;
    -t)
	timeout=$2
	shift
	shift
	;;
    -m)
	message="$2"
	shift
	shift
	;;
    -*)
	usage
	;;
    *)
	break
    esac
done

[ $# -gt 0 ] || usage

logfile="$1"
shift
builddir="$1"
shift
[ $# -eq 0 ] || usage

cleanup()
{
    rm -f $pidfile
    exit 0
}

#trap cleanup 0 1 3 15

echo $$ > $pidfile

declare -A stamps

find_logs()
{
    for f in $(find $builddir -name '*.log' \
			       ! -name config.log \
			       ! -path '*/ada/acats?/tests/*.log' \
			       ! -path '*/libbacktrace/*.log')
    do
	if [ ! -v stamps[$f] ]; then
	    stamps[$f]=$(date -u -r $f '+%s')
	fi
    done
}

# wait for test startups
sleep 30
find_logs

# activity in the main log file
sleep 10
st_logfile=$(date -u -r $logfile '+%s')

sleep 10

while true; do
    find_logs
    sleep 10
    stamp=$(date -u -r $logfile '+%s')
    if [ $stamp -gt $st_logfile ]; then
	# there is still action in the primary logfile. do nothing.
	st_logfile=$stamp
    else
	activity=0
	for log in "${!stamps[@]}"; do
	    [ -f $log ] || continue
	    stamp=$(date -u -r $log '+%s')
	    if [ $stamp -gt ${stamps[$log]} ]; then
		if [ $activity -eq 0 ]; then
		    echo
		fi
		echo "[$(date -u -r $log '+%T')] $log: $message"
		tail -3 $log
		activity=$(expr $activity + 1)
		stamps[$log]=$stamp
	    fi
	done
	if [ $activity -gt 0 ]; then
	    # already emitted messages above
	    echo
	else
	    # nothing changed in the other log files. maybe a timeout ...
	    :
	fi
    fi
    sleep $timeout
done

exit 0