There are two USERS on this computer: jdl and experiment
CRONTAB setup (for experiment(executed every minute):
USER=experiment
HOME=/home/experiment
SHELL=/bin/bash
PATH=/home/experiment/bin:/home/experiment/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
XAUTHORITY=/home/experiment/.Xauthority
DISPLAY=:0
/1 * * * /home/experiment/monitor
From the command prompt running a script(monitor) with: (yields Inactive)
if (gnome-screensaver-command -q | grep "is inactive"); then
# Inactive screensaver
echo "screensaver: Inactive">>log_log.txt
elif (gnome-screensaver-command -q | grep "is active"); then
# Active screensaver
echo "screensaver: Active">>log_log.txt
else
# N/A active screensaver
echo "screensaver: N/A">>log_log.txt
fi
But from CRONTAB(running the script: monitor)... running the same script: (yields N/A) as the scope is not a particular user
How to get the screensaver status for a particular user when the script is run from CRONTAB?
/usr/bin/gnome-screensaver-command
rather thangnome-screensaver-command
; ☐begin your script withexport DISPLAY=':0.0'
; ☐set$PATH
at the top of your script – bitinerant Dec 23 '20 at 05:49systemd.timer
and start it as a user service. – Dec 23 '20 at 09:13