【问题标题】:script not running before sleep脚本在睡眠前未运行
【发布时间】: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


【解决方案1】:

这有什么好运气吗?我写了一个脚本在醒来后运行,我得到了类似的错误。该脚本应该在从睡眠中醒来时关闭笔记本电脑的显示屏。

case "${1}" in
resume|thaw)
screen_status=$(xset -q -display :0.0 | tail -1 | sed 's/^[ \t]*//g')

if [[ "$screen_status" = "Monitor is On" ]]; then
    sleep 1 && xset -display :0.0 dpms force off
fi
;;
esac

但我收到以下错误:

No protocol specified xset: unable to open display ":0.0"

我试图让它在无法显示时将 screen_status 设置为“监视器已关闭”,以便它触发条件以执行 xset,但这也不起作用,因为它可以' t 访问显示。同时,我将 xfce4-power-manager 设置为在 1 分钟后关闭屏幕。等待一分钟总比没有好!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 2016-05-31
    • 1970-01-01
    • 2011-03-05
    • 2021-12-11
    • 2021-10-22
    • 1970-01-01
    相关资源
    最近更新 更多