我在rasperry pi上使用xdotool来刷新iceaweasel浏览器。现在,我想在局域网服务器启动后重新加载网页。
为此,我在Raspberry上编写了一个PHP脚本(refresh.php):
<?php
exec("sh /var/www/refresh.sh");
?>
resfresh.sh
export DISPLAY=:"0.0"
XAUTHORITY=/home/pi/.Xauthority
xdotool getactivewindow
xdotool key F5
如果我从控制台启动PHP脚本,刷新工作!如果我从外部浏览器启动PHP,刷新不工作!
Apache的错误日志:
No protocol specified
Error: Can't open display: (null)
Failed creating new xdo instance
我认为xdotool和用户www-data有问题。
有人能帮我吗?
添加www-data权限来执行系统工具
DISPLAY=:0 xhost + local:www-data
在你的脚本上/refresh.sh
#!/bin/bash
export DISPLAY=:0 && xdotool key F5
在php文件
<?php
shell_exec("/refresh.sh " . $phone);
?>
然后添加可执行权限到你的PHP文件
sudo chmod +x refresh.php