문제

I need to detect user inactivity on my Linux system, to poweroff it (quite headless wife, and quite expensive electric bills... :-).

I need to schedule the script (in crontab), so no X-depending tool will work, I suppose (no $DISPLAY available).

Any thoughts?

UPDATE

For "user inactivity" I mean user input inactivity (mouse and keyboard).

도움이 되었습니까?

해결책

Xautolock may the right tool for you. It allows you to specify a amount of minutes of inactivity after which a command should get triggered.

다른 팁

You might consider checking how long the screen saver has been running.

#!/bin/bash

screensaver="atlantis"

t=$(
    # check for the screensaver
    ps h -o start -C $screensaver          |\
    # hh:mm:ss -> seconds
    awk -F: '{print $1"*3600+"$2"*60+"$3}' |\
    bc -l  2>/dev/null  | sort -n | tail -1
)

if [ "$t" == "" ]
then
    exit 0
fi

n=$(
    date "+%T"                             |\
    awk -F: '{print $1"*3600+"$2"*60+"$3}' |\
    bc -l  2>/dev/null
)

runtime=$(( $n - $t ))

if [ $runtime -gt 3600 ] || [ $runtime -lt 0 ]
then
    echo shutdown -h now 
fi

Using the time value requires subtracting now from then to get the run time. Also, in my case, the screensaver program which appears in the process table will vary depending on which screensaver is selected. So, the above program assumes that 'atlantis' is the current screen saver.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top