3

I'm trying to execute a xdotool operation (move mouse) on the user's display from a root shell but I get:

# DISPLAY=:0 mousemove_relative 1 1
No protocol specified
Error:Can't open display: (null)
Failed creating new xdo instance
#

Why does this not work?


the script:

#!/bin/bash

exec=`/usr/sbin/nethogs -t -c 1| awk '/smbd/ {print $2}'`

sent=$exec

echo "result: "$sent
sent=$(echo "($sent+0.5)/1" | bc)
echo "rounded: "$sent
if [[ $sent -gt 0 ]]
then 
    echo "music is playing"
    `DISPLAY=:0 xdotool mousemove_relative 1 1`
else
    echo "quiet"
fi

I get this in /var/mail/root:

Waiting for first packet to arrive (see sourceforge.net bug 1019381)
result: 6.73438
rounded: 7
music is playing
No protocol specified
Error: Can't open display: (null)
Failed creating new xdo instance
4
  • I suggest to use user which owns this X11 session.
    – Cyrus
    Sep 9, 2017 at 19:00
  • Yes, but I have to run this script as root for reasons that will be out of scope of the question asked...
    – stdcerr
    Sep 9, 2017 at 19:02
  • Is mousemove_relative a shell script or function? If so, can you show the contents to us? Sep 9, 2017 at 22:47
  • @MarkPlotnick it's a script, please see above, it'll run as a cront job from root's table
    – stdcerr
    Sep 9, 2017 at 23:42

1 Answer 1

8

I found the answer on https://www.reddit.com/r/linux/comments/2clob0/help_with_cron_though_its_probably_not_really_a/?st=j7e4jv37&sh=e83bf930

I had to add the following to the script:

export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .