【发布时间】:2016-05-30 19:46:22
【问题描述】:
我正在尝试创建一个在睡觉前运行的脚本。有人可以告诉我我在这里做错了什么吗?当我在终端中运行命令时,此脚本运行完美。
king@death-star /etc/pm/sleep.d $ ls
total 1MB
drwxr-xr-x 2 root root 1MB May 30 15:21 .
drwxr-xr-x 5 root root 1MB Nov 28 2015 ..
-rwxr-xr-x 1 root root 1MB Jun 26 2015 10_grub-common
-rwxr-xr-x 1 root root 1MB Dec 6 2013 10_unattended-upgrades-hibernate
-rwxr-xr-x 1 root root 1MB May 22 2012 novatel_3g_suspend
-rwxr-xr-x 1 root root 1MB May 30 15:20 revert_kb_on_sleep
king@death-star /etc/pm/sleep.d $ cat revert_kb_on_sleep
sh -c "/home/king/Desktop/Scripts/rotate_desktop normal; /home/king/Desktop/Scripts/misc/my_keyboard on"
日志输出:
$ cat /var/log/pm-suspend.log
Running hook /etc/pm/sleep.d/revert_kb_on_sleep suspend suspend:
Can't open display
Can't open display
xrandr: --rotate requires an argument
Try 'xrandr --help' for more information.
No protocol specified
Unable to connect to X server
/etc/pm/sleep.d/revert_kb_on_sleep suspend suspend: success.
Mon May 30 15:23:39 EDT 2016: performing suspend
Mon May 30 15:27:59 EDT 2016: Awake.
Mon May 30 15:27:59 EDT 2016: Running hooks for resume
Running hook /etc/pm/sleep.d/revert_kb_on_sleep resume suspend:
Can't open display
Can't open display
xrandr: --rotate requires an argument
Try 'xrandr --help' for more information.
No protocol specified
Unable to connect to X server
/etc/pm/sleep.d/revert_kb_on_sleep resume suspend: Returned exit code 1.
【问题讨论】:
-
从守护进程运行时,X-Windows 上下文/DISPLAY 环境变量似乎未设置 - 您可以尝试将
-d :0.0(显示选项)之类的内容添加到 xrandr,然后希望您不会遇到权限问题。我觉得您尝试做的事情不属于 sleep.d 目录,但也许您的窗口管理器/桌面设置有一个可以指定一些操作的地方...? -
我对 linux mint 相当陌生,如果我发现任何东西,我会做一些研究并发表评论。谢谢你的提示。对于将来阅读此内容的任何人,
-d :0.0将导致权限问题。我在最初让脚本工作时发现了这一点。 -
没有运气找到另一种方法来做到这一点......有人有什么想法吗?
-
找出正在运行脚本的用户, - 要么允许该用户对您的用户使用 sudo 并尝试
-d :0.0的事情 - 或尝试xhost +local并尝试使用或不使用来自用户的 sudo运行睡眠脚本 - 如果你喜欢它,我会为我的声誉创建一个答案;-)
标签: bash linux-mint xrandr