Time Since Idle
Log the time when the user resumes from standby
$ nano /usr/lib/systemd/system-sleep/sinceidle
#!/bin/sh
case $1 in
post)
logger "sinceidle resumed"
;;
esac
Grep the time out of the syslog
$ grep sinceidle /var/log/syslog | tail -n 1
Time since last resume
$ cat sinceresume.sh
#!/bin/bash
# Get the syslog entry from the command line argument
syslog_entry="$(grep sinceidle /var/log/syslog | tail -n 1)"
# Extract the timestamp from the syslog entry using awk
timestamp=$(echo "$syslog_entry" | awk '{print $1, $2, $3}')
echo "timestamp: $timestamp"
# Convert the extracted timestamp to a Unix timestamp
syslog_unix_timestamp=$(date -d "$timestamp" "+%s")
# Get the current Unix timestamp
current_unix_timestamp=$(date "+%s")
# Calculate the number of seconds since the syslog timestamp
seconds_since_syslog=$((current_unix_timestamp - syslog_unix_timestamp))
echo "Seconds since syslog timestamp: $seconds_since_syslog"