blob: 637af899c6b6616033f8eb2dc486084ba3a0d251 (
plain)
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
|
#!/bin/sh
# Displays new nginx log entries from ylog.
# Updates every 30 minutes via dwmblocks.
# Left click: show new entries and mark as seen
# Middle click: force refresh
# Right click: help
CACHE_DIR="/tmp/ylog_sb"
PREV="$CACHE_DIR/prev"
CURR="$CACHE_DIR/curr"
NEW="$CACHE_DIR/new"
LOCK="$CACHE_DIR/lock"
mkdir -p "$CACHE_DIR"
fetch_logs() {
us_today=$(TZ=America/New_York LC_TIME=C date +%d/%b)
us_yesterday=$(TZ=America/New_York LC_TIME=C date -d 'yesterday' +%d/%b)
ssh -o BatchMode=yes -o ConnectTimeout=10 root@thesiah.xyz \
"cat /var/log/nginx/diary.us.log /var/log/nginx/recordings.us.log /var/log/nginx/peertube.us.log 2>/dev/null" \
2>/dev/null | grep -E "$us_today|$us_yesterday" | grep -E '[0-9]{2}:[0-9]{2}:[0-9]{2} ' | grep -v '59\.19\.56\.8' | sort -u
}
update() {
# Prevent concurrent updates
if [ -f "$LOCK" ]; then
kill -0 "$(cat "$LOCK")" 2>/dev/null && return
fi
echo $$ > "$LOCK"
fetch_logs > "$CURR" 2>/dev/null
total=$(wc -l < "$CURR")
if [ -f "$PREV" ]; then
# Find lines in curr that are not in prev
comm -23 "$CURR" "$PREV" > "$NEW"
else
cp "$CURR" "$NEW"
fi
new_count=$(wc -l < "$NEW")
[ -t 1 ] && echo "[ylog] fetched $total lines, $new_count new" >&2
rm -f "$LOCK"
}
mark_seen() {
[ -f "$CURR" ] && cp "$CURR" "$PREV"
: > "$NEW"
}
case $BLOCK_BUTTON in
1)
if [ -s "$NEW" ]; then
notify-send "🌐 New log entries" "$(cat "$NEW" | sed 's/^[^ ]* //' | cut -c1-120 | tail -20)"
mark_seen
pkill -RTMIN+21 "${STATUSBAR:-dwmblocks}"
else
notify-send "🌐 Ylog" "No new entries."
fi
;;
2)
notify-send "🌐 Ylog" "Refreshing..."
update
pkill -RTMIN+21 "${STATUSBAR:-dwmblocks}"
;;
3)
notify-send "🌐 Ylog module" "- Shows new nginx log entries (diary/recordings/peertube US)
- Updates every 30 minutes
- Left click: show new entries & mark seen
- Middle click: force refresh"
;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
*)
# Regular update (called by dwmblocks interval)
update
;;
esac
# Display
if [ -s "$NEW" ]; then
count=$(wc -l < "$NEW")
echo "🌐$count"
fi
|