脚本在睡觉前没有运行

时间:2016-05-30 19:46:22

标签: bash linuxmint xrandr

我正在尝试创建一个在睡觉前运行的脚本。谁能告诉我这里做错了什么?当我在终端中运行命令时,此脚本运行完美。

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.

1 个答案:

答案 0 :(得分:0)

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

=================================
:: PHP ini Settings::
=================================

default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=6 

=================================
:: .htaccess Settings::
=================================

DefaultLanguage en-US
AddDefaultCharset UTF-8

=================================
:: HTML Header Page::
=================================

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

=================================
:: PHP Codeigniter index.php ::
=================================

header('Content-Type: text/html; charset=UTF-8');

=================================
:: Codeigniter config.php ::
=================================

$config['charset'] = 'UTF-8';

=================================
:: Codeigniter database.php ::
=================================

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

=================================
:: Codeigniter helper function (optional)
=================================

if(!function_exists('safe_utf_string')){
    function safe_utf_string($utf8string= ''){
        $utf8string = htmlspecialchars($utf8string, ENT_QUOTES, 'UTF-8');
        return mb_convert_encoding($utf8string, 'UTF-8');
    }
}

但是我收到以下错误:

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

我试图让它将screen_status设置为“Monitor is off”,当它无法显示时,因此无论如何它都会触发执行xset的条件,但这也不起作用,因为它可以' t访问显示器。与此同时,我设置xfce4-power-manager在1分钟后关闭屏幕。等不了一分钟总比什么都好!