summarylogtreecommitdiffstats
path: root/another-minute.sh
diff options
context:
space:
mode:
authorivanp72022-11-12 21:32:57 +0300
committerivanp72022-11-18 15:50:10 +0300
commit52d8d1286ed0fa97d9151ba91790abf180ac27de (patch)
treefd2053d02e09098f481c3d1792f83d73b3b85932 /another-minute.sh
downloadaur-usage-logging.tar.gz
initial commit
Diffstat (limited to 'another-minute.sh')
-rwxr-xr-xanother-minute.sh20
1 files changed, 20 insertions, 0 deletions
diff --git a/another-minute.sh b/another-minute.sh
new file mode 100755
index 000000000000..bc7068e8b0be
--- /dev/null
+++ b/another-minute.sh
@@ -0,0 +1,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"
+