-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathforklogq
102 lines (91 loc) · 4.65 KB
/
forklogq
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
#! /usr/bin/env bash
function print_usage () {
echo "forklog help:"
echo
echo "SYNOPSIS: Extremely versatile and powerful log parsing tool. See parameters below."
echo " The 'forklog running:' first line of output is the bash command generated"
echo " after interpretation of the switches that actually produces the resulting output,"
echo " albeit prior to some path variable substitution."
echo " As many search terms as desired can be added by the various switches."
echo " A line will show if any one of the search terms are found in that line."
echo " The file ftconfigs/config.forklog allows for setting some default filters"
echo " such as a specific date range or only the previous X days worth of log entries."
echo " Note that the config setting FORKLOGTAIL effectively sets the maximum number"
echo " of lines this tool can output. This number can be overridden with -t switch."
echo " Running 'forklog forkname' with no switches produces the last FORKLOGTAIL"
echo " lines of the log with no filters or search terms."
echo
echo "PARAMETERS/SWITCHES:"
echo " forkname Required. All others optional."
echo " -e | --error Adds 'ERROR' as a search term."
echo " -w | --warning Adds 'WARNING' as a search term."
echo " -h | --harv Adds 'harvester' as a search term."
echo " -p | --proof Adds any positive # of found proofs as a search term."
echo " -g 'word' | --grep 'word' Adds 'word' as a search term. Multiple uses allowed."
echo " -l 10 | --lastxdays 10 Shows only results for the last 10 days."
echo " -s YYYY-MM-DD | --startdate YYYY-MM-DD Do not show results prior to this date. If both this"
echo " and -l / --lastxdays are set, this is used."
echo " -u | --enddate YYYY-MM-DD Do not show results after this date."
echo " -t 100 | --tail 100 Tails the last 100 lines of the result. forklog always"
echo " tails FORKLOGTAIL lines as set in ftconfigs/"
echo " config.forklog. Use -t to override that default."
echo " -help | --help Show this information again."
echo
exit 0
}
FORKNAME=$1
VALIDATEFORKNAME='No'
. ftinit.sh
if [[ ! -f $FORKTOOLSHIDDENDIRS/.$FORKNAME/mainnet/log/debug.log ]]; then
echo "Invalid forkname or configured path: '$FORKTOOLSHIDDENDIRS/.$FORKNAME/mainnet/log/debug.log' does not exist."
exit
fi
STARTDATE=$FORKLOGSTARTDATE
LASTXDAYS=$FORKLOGLASTXDAYS
ENDDATE=$FORKLOGENDDATE
TAILLENGTH=$FORKLOGTAIL
GREPTERM=''
FIRSTLOOP=1
while [[ $# -gt 0 ]]; do
if [[ $FIRSTLOOP = 1 ]]; then
FORKNAME="$1"
FIRSTLOOP=0
shift
continue
fi
opt="$1"
case "$opt" in
"-e"|"--error" ) GREPTERM=$(printf "%s -e ERROR" "$GREPTERM" ); shift;;
"-w"|"--warning" ) GREPTERM=$(printf "%s -e WARNING" "$GREPTERM" ); shift;;
"-p"|"--proofs" ) GREPTERM=$(printf "%s -e 'Found [1.9].* proofs'" "$GREPTERM" ); shift;;
"-h"|"--harv" ) GREPTERM=$(printf "%s -e harvester" "$GREPTERM" ); shift;;
"-g"|"--grep" ) shift; GREPTERM=$(printf "%s -e $1" "$GREPTERM" ); shift;;
"-l"|"--lastxdays" ) shift; LASTXDAYS="$1"; SETLASTXDAYS="$1"; shift;;
"-s"|"--startdate" ) shift; STARTDATE="$1"; SETSTARTDATE="$1"; shift;;
"-u"|"--enddate" ) shift; ENDDATE="$1"; ENDDATE=$(DateOffset +1 $ENDDATE); shift;;
"-t"|"--tail" ) shift; TAILLENGTH="$1"; shift;;
"-help" | "--help" ) print_usage;;
* ) echo 'ERROR: Invalid option: '$opt >&2
exit 1;;
esac
done
if [[ $LASTXDAYS != '' ]]; then
STARTFROM=$(echo "(($LASTXDAYS - 1))" | bc)
STARTFROM=$(DateOffset -${STARTFROM})
fi
if [[ $STARTDATE != '' && ($SETLASTXDAYS = '' || $SETSTARTDATE != '') ]]; then
STARTFROM=$STARTDATE
fi
BUILDEXPR=$(echo 'awk -v start='"$STARTFROM"' -v end='"$ENDDATE")
BUILDEXPR=$(echo $BUILDEXPR "'"'$0 >= start && $0 <= end'"'" '$FORKTOOLSHIDDENDIRS/.$FORKNAME/mainnet/log/debug.log*')
if [[ $GREPTERM != '' ]]; then
BUILDEXPR=$(echo $BUILDEXPR " | grep $GREPTERM")
fi
BUILDEXPR=$(echo $BUILDEXPR " | sort")
if [[ $TAILLENGTH != '' ]]; then
BUILDEXPR=$(echo $BUILDEXPR " | tail -$TAILLENGTH")
fi
IFS=''
echo "forklog running: '" $BUILDEXPR "'"
echo $(eval $BUILDEXPR)
IFS=$DEFAULT_IFS