From Capum321, 1 Year ago, written in Plain Text.
#
# File name: getIdleTimeN - C PROGRAM compiled to executable - it gets idle time from X.
#
#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
int main(void) {
// Display *dpy = XOpenDisplay(NULL);
Display *dpy = XOpenDisplay(":0");
if (!dpy) {
fprintf(stderr, "unable to connect to display");
return(1);
}
XScreenSaverInfo *info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
printf("%lu", info->idle);
return(0);
}
#
# compilation output
#
$ gcc -o getIdleTime getIdleTime.c -lXss -lX11
OK
#
# File name: VerinaN - BASH script built upon getIdleTime, which N version is current.
#
#!/bin/bash
idleAfter=7200000 # consider inactive after (7200 s * 1000) ms = 120 min
contador=$(/path/to/getIdleTime4)
if [ "$?" != 0 ]; then
echo -e "\nERROR: getIdleTime failed"; exit 1;
fi
if [ "$contador" -gt "$idleAfter" ]; then
# echo $contador # just for debug purposes.
rtcwake -s 7200 -m mem # enter cmd
fi
sleep 1 # polling interval
exit
#
# File name: Verina.service - SYSTEMD SERVICE which is triggered to run the BASH wich N version is current.
#
[Unit]
Description=Verif of Inact for Off Time Schedule every 2 h
[Service]
User=`user id n`
ExecStart=/bin/bash /path/to/VerinaN
#
# `journalctl -u Verina.service` output
#
$ journalctl -u Verina.service
Set 25 08:44:18 GotaSerena systemd[1]: Started Verif de Inat para Esc de Trab cada 2 h.
Set 25 08:44:18 GotaSerena bash[21394]: rtcwake: /dev/rtc0: unable to find device: Permission denied
Set 25 08:44:18 GotaSerena bash[21394]: rtcwake: assuming RTC uses UTC ...
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}