如何将命令从控制台 shell 脚本(ssh)定向到 xserver

如何将命令从控制台 shell 脚本(ssh)定向到 xserver

我正在尝试从运行在 raspberry pi 上的 xserver 获取一个值。该命令DISPLAY=:0 xssstate -i在命令行上有效,但在运行脚本时无效。

在本地运行脚本可以完美运行,但是通过 ssh 运行它时却不行

脚本:

enter code here

#!/bin/bash

# Wanted trigger timeout in milliseconds.
IDLE_TIME=$((10*1000))

triggered=0

while [ 1 -eq 1 ]
do
sleep 1
sstime=$(DISPLAY=:0 xssstate -i)
echo "idletime $IDLE_TIME"
echo "sstime $sstime"
if [ "$sstime" -gt "$IDLE_TIME" ] || [ "$triggered" -eq 0 ]
then
        echo 235 > /sys/waveshare/rpi_backlight/brightness
        triggered=1
elif [ "$sstime" -lt "$IDLE_TIME" ] || [ "$triggered" -eq 1 ]
then
        echo 0 > /sys/waveshare/rpi_backlight/brightness
        triggered=0
else
        triggered=0
fi

done

输出:

No protocol specified
Cannot open display.
idletime 10000
sstime
./backLTctrl.sh: line 15: [: : integer expression expected
No protocol specified
Cannot open display.
idletime 10000
sstime
./backLTctrl.sh: line 15: [: : integer expression expected
./backLTctrl.sh: line 19: [: : integer expression expected
No protocol specified
Cannot open display.
idletime 10000
sstime
./backLTctrl.sh: line 15: [: : integer expression expected
No protocol specified
Cannot open display.
idletime 10000
sstime
./backLTctrl.sh: line 15: [: : integer expression expected
./backLTctrl.sh: line 19: [: : integer expression expected

相关内容