在用户显示上运行命令,因为 root 无法按预期工作

在用户显示上运行命令,因为 root 无法按预期工作

我正在尝试xdotool从 root shell 在用户显示器上执行操作(移动鼠标),但我得到:

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

为什么这不起作用?


剧本:

#!/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

我得到这个/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

答案1

我找到了答案https://www.reddit.com/r/linux/comments/2clob0/help_with_cron_though_its_probously_not_really_a/?st=j7e4jv37&sh=e83bf930

我必须将以下内容添加到脚本中:

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

相关内容