Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Last active November 3, 2018 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmacaulay/c7edb6699aebf2204d54f8872ae5c41d to your computer and use it in GitHub Desktop.
Save jamesmacaulay/c7edb6699aebf2204d54f8872ae5c41d to your computer and use it in GitHub Desktop.
#!/bin/bash
lastlast=$(last --time-format=iso -1 -R | head -1 | awk '{ print $3 "\n" $5 }' | xargs -n1 date +%s -d 2> /dev/null)
lastuserinputs=$(who -s | awk '{ print $2 }' | (cd /dev && xargs stat -c '%X'))
events=$lastlast$'\n'$lastuserinputs
sincelatestevent=$(echo "$events" | sort -rn | head -1 | awk '{ print '"$(date +%s)"'-$1 }')
uptime=$(cat /proc/uptime | sed -n 's/\([0-9]*\).*/\1/p')
durations=$sincelatestevent$'\n'$uptime
idletime=$(echo "$durations" | sort -n | head -1)
echo "$idletime"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment