All pastes #1903264 Raw Edit

idlelog.sh

public shellscript v1 · immutable
#1903264 ·published 2010-07-18 23:50 UTC
rendered paste body
#!/bin/bashthreshold=300 # how many seconds to consider idlegoneidle=0while sleep 1;do  idleplus=$(xidles)  if [ $idleplus -ge $threshold ];then    if [ $goneidle -eq 0 ];then      goneidle=1      nowtime=$(date +%s)      idletime=$((nowtime-idleplus))      echo "went idle @ $(date -d @$idletime)" >>~/.idlelog    fi  else    if [ $goneidle -gt 0 ];then      goneidle=0      nowtime=$(date +%s)      returntime=$((nowtime-idleplus))      gfs=$((returntime-idletime))      gonefor="$((gfs/3600/24))d $((gfs/3600%24))h $((gfs/60%60))m $((gfs%60))s"      echo "came back @ $(date -d @$returntime) ($gonefor)" >>~/.idlelog    fi  fidone