You are not logged in.
How can I added a check to see if the user is logged in graphically to a crontab line? I do not want the script cron is targeting to run unless the user is logged into X. Google has been surprisingly unhelpful.
Thanks all.
Last edited by graysky (2013-01-09 23:28:10)
Offline
I feel like I might be missing part of the problem ... wouldn't this work:
[[ -n $DISPLAY ]] && /path/to/something/to/doEDIT: ah, I suppose I am, the DISPLAY variable is only shared within a session.
Last edited by Trilby (2013-01-09 23:28:14)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Stellar! I think that will work. Thx.
Offline
I edited while you were posting. I hope that could work, but it depends on how the user crontab is running.
If (when) that fails, you could look into parsing the output of `ps` with flags to get just the appropriate user's processes and check for xinit or something similar.
EDIT: this should do
[[ -n "$(ps -eo args | grep -E "^X")" ]] && /something/to/dobut then this is much simpler if you have pgrep installed (which I sppose you have to if you have ps)
pgrep -c X >/dev/null && /something/to/doLast edited by Trilby (2013-01-09 23:43:28)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Another approch to this is systemd. The following command returns -3 if X is not active, and 0 otherwise.
systemctl is-active graphical.target --quietHowever the safer method is pgrep, because X can be started while graphical.target is not active.
Last edited by teateawhy (2013-01-10 20:25:03)
Offline