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:


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


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

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
  • I suggest to use user which owns this X11 session. – Cyrus Sep 9 '17 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... – cerr Sep 9 '17 at 19:02
  • Is mousemove_relative a shell script or function? If so, can you show the contents to us? – Mark Plotnick Sep 9 '17 at 22:47
  • @MarkPlotnick it's a script, please see above, it'll run as a cront job from root's table – cerr Sep 9 '17 at 23:42

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.