如何在暂停/从暂停返回时运行命令?

如何在暂停/从暂停返回时运行命令?

我经常挂起笔记本电脑 (pm-suspend),有时也会经常挂起台式电脑 (pm-suspend-hybrid)。我使用的是最新版 ubuntu (13.10,saucy)。

有没有办法让我在进入挂起状态时或退出挂起状态后立即运行命令?我想终止所有打开的输出 ssh 连接并停止 offlineimap,因为这些连接的超时往往很烦人。有什么想法吗?

答案1

来自手册页pm-action(8)

/etc/pm/sleep.d, /usr/lib/pm-utils/sleep.d
     Programs in these directories (called hooks) are combined
     and executed in C sort order before suspend and hibernate
     with as argument ´suspend´ or ´hibernate´. Afterwards they
     are called in reverse order with argument ´resume´ and
     ´thaw´ respectively. If both directories contain a similar
     named file, the one in /etc/pm/sleep.d will get preference.
     It is possible to disable a hook in the distribution
     directory by putting a non-executable file in
     /etc/pm/sleep.d, or by adding it to the HOOK_BLACKLIST
     configuration variable.

因此你可以简单地放置如下的 shell 脚本:

#!/bin/bash

case "$1" in
suspend|hibernate)
    actions to
    take
    on suspend
    or hibernate
    ;;
resume|thaw)
    other actions
    to trigger
    on resume
    ;;
esac

进入例如99-myhooks.sh并使其可执行。

Enter~.Enter顺便说一句,您可以通过进入SSH 会话来终止过时的 SSH 连接。

相关内容