From 4906b13a3806e6a6e64f277ec37a62f86c1c0b57 Mon Sep 17 00:00:00 2001 From: mwiegand Date: Sat, 12 Feb 2022 21:16:08 +0100 Subject: [PATCH] use uptime since last wake instead of boot --- bundles/wol-sleeper/files/suspend_if_idle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bundles/wol-sleeper/files/suspend_if_idle b/bundles/wol-sleeper/files/suspend_if_idle index 1519321..6e452c4 100644 --- a/bundles/wol-sleeper/files/suspend_if_idle +++ b/bundles/wol-sleeper/files/suspend_if_idle @@ -1,10 +1,12 @@ #!/bin/bash -UPTIME=$(cat /proc/uptime | cut -d. -f1) +WOKE=$(expr $(journalctl -t systemd-sleep -b 0 -o json MESSAGE="System resumed." -n1 | jq -r .__REALTIME_TIMESTAMP) / 1000000) +NOW=$(date +%s) +UPTIME=$(expr $NOW - $WOKE) MIN_UPTIME=$(expr 60 \* 20) if [[ "$UPTIME" -lt "$MIN_UPTIME" ]] then - echo "ABORT: uptime ($UPTIME) lower than min ($MIN_UPTIME)" + echo "ABORT: uptime ($UPTIME s) lower than minimum ($MIN_UPTIME s)" exit 0 fi