summarylogtreecommitdiffstats
path: root/another-minute.sh
blob: bc7068e8b0be40666063fdef8a4985230bd4a78b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

DATE_TIME="$(date +'%F.%u %_H:%M')"
DATE="${DATE_TIME%% *}"
TIME="${DATE_TIME##* }"
HOUR="${TIME%%:*}"
MINUTE="${TIME##*:}"

LINE="$(($HOUR + 1))"

LOGDIR="/var/log/usage"
LOGFILE="$LOGDIR/$DATE"

[ -d "$LOGDIR" ] || mkdir -p -- "$LOGDIR"

[ -f "$LOGFILE" ] ||
    dd if=/dev/zero bs=1 count=$((24*60)) 2> /dev/null | tr '\0' '.' | fold -w 60 > "$LOGFILE"

sed -i -E "${LINE}s/^(.{$MINUTE})./\1#/" "$LOGFILE"