-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagegen.sh
executable file
·185 lines (161 loc) · 4.19 KB
/
pagegen.sh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh
SELF="$(basename $0)"
USAGE="Generate HTML status page.
USAGE
-stats path
Required. Directory with stats files.
-help
Print this help.
EXAMPLE
$SELF -stats /var/log/sitesmonitor > /var/www/sitesmonitor/status.html
Written by BrainFucker."
## Print messages to stderr
errlog () {
echo "$@" 1>&2
}
getfilemodified () {
stat "$1" | grep 'Modify:' | sed 's/Modify://'
}
## Args parser
## Supported arg formats:
## -arg --arg (both are identical)
## -arg value
## -arg=value
parse_args() {
local ARG _PREV_ARG _ARG _VAR _VAL _ARGN SKIP
for ARG in "$@"; do
case "$ARG" in
--) _PREV_ARG=''
SKIP=1 ;;
-*) if [ -z "$SKIP" ]; then
_ARG="$(echo -n "$ARG" | sed 's/^-\+//' | sed 's/-/_/g' | tr -d '\r' | tr '\t\v\n' ' ')"
case "$_ARG" in
*=*) _PREV_ARG=''
_VAR="$(echo -n "$_ARG" | sed 's/=.*//')"
_VAL="$(echo -n "$_ARG" | sed 's/.\+=//')"
if [ -z "$_VAL" ]; then
_VAL=0
fi
eval "_arg_$_VAR=\$_VAL" ;;
*) _PREV_ARG="_arg_$_ARG"
eval "_arg_$_ARG=1" ;;
esac
fi ;;
*) if [ -n "$_PREV_ARG" ]; then
eval "$_PREV_ARG=\$ARG"
_PREV_ARG=''
else
_ARGN=$((_ARGN+1))
eval "_arg$_ARGN=\$ARG"
fi ;;
esac
done
} # parse_args()
parse_args "$@"
if [ -z "$1" ] || [ -n "$_arg_help" ] || [ -n "$_arg_h" ]; then
errlog "$USAGE"
exit 0
fi
if [ -z "$_arg_stats" ] || [ ! -d "$_arg_stats" ]; then
errlog "No such directory '$_arg_stats'. Run '$SELF -help' to see usage."
exit 1
fi
export LANG=C
echo '<!DOCTYPE html>
<html>
<head>
<title>Sites monitoring status</title>
<meta charset="UTF-8">
<style>
h2 {
margin: 1em;
}
div.type {
padding-left: 1em;
}
div.infoblock {
border: 1px solid black;
margin-bottom: 1em;
}
div.tbl {
display: table;
width: 100%;
background-color: #c0c0c0;
}
div.tr {
display: table-row;
}
div.td {
display: table-cell;
}
div.time{
text-align: right;
}
pre {
background-color: #eeeeee;
padding: 1em;
margin: 0;
}
</style>
</head>
<body>'
for FILE in "$_arg_stats/TASK__"*
do
TASKNAME="$(basename "$FILE" | sed 's/TASK__//')"
TIME="$(getfilemodified "$FILE")"
echo '<div class="infoblock">'
echo "<h2>$TASKNAME" | sed 's#\.err#</h2>\n<div class="tbl"><div class="tr"><div class="type td">stderr</div>%#' | \
sed 's#\.out#</h2>\n<div class="tbl"><div class="tr"><div class="type td">stdout</div>%#' | \
sed 's#\.status#</h2>\n<div class="tbl"><div class="tr"><div class="type td">status</div>%#' | \
sed "s#%#<div class=\"time td\">$TIME</div></div></div>#"
echo "<pre>"
cat "$FILE"
echo "</pre>"
echo '</div>'
echo ''
done
echo '<div class="infoblock">'
echo '<h2>Last report</h2>'
echo '<div class="tbl"><div class="tr"><div class="type td">stderr</div><div class="time td">'
getfilemodified "$_arg_stats/REPORT.txt"
echo '</div></div></div>'
echo '<pre>'
if [ -f "$_arg_stats/REPORT.txt" ]; then
cat "$_arg_stats/REPORT.txt"
else
echo 'File not found'
fi
echo '</pre>'
echo '</div>'
echo ''
echo '<div class="infoblock">'
echo '<h2>Last stdout</h2>'
echo '<div class="tbl"><div class="tr"><div class="type td">stderr</div><div class="time td">'
getfilemodified "$_arg_stats/TASK.OUT"
echo '</div></div></div>'
echo '<pre>'
if [ -f "$_arg_stats/TASK.OUT" ]; then
cat "$_arg_stats/TASK.OUT"
else
echo 'File not found'
fi
echo '</pre>'
echo '</div>'
echo ''
echo '<div class="infoblock">'
echo '<h2>Last stderr</h2>'
echo '<div class="tbl"><div class="tr"><div class="type td">stderr</div><div class="time td">'
getfilemodified "$_arg_stats/TASK.ERR"
echo '</div></div></div>'
echo '<pre>'
if [ -f "$_arg_stats/TASK.ERR" ]; then
cat "$_arg_stats/TASK.ERR"
else
echo 'File not found'
fi
echo '</pre>'
echo '</div>'
echo ''
echo '</body>
</html>
'