如何在挂起/从挂起返回时运行命令?

Fre*_*idt 9 linux hibernate suspend ubuntu

我经常暂停我的笔记本电脑 (pm-suspend),有时我的台式机 (pm-suspend-hybrid) 相当频繁。我正在使用最新的 ubuntu(13.10,俏皮)。

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

And*_*ese 10

从联机帮助页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.
Run Code Online (Sandbox Code Playgroud)

因此,您可以简单地放置这样的 shell 脚本:

#!/bin/bash

case "$1" in
suspend|hibernate)
    actions to
    take
    on suspend
    or hibernate
    ;;
resume|thaw)
    other actions
    to trigger
    on resume
    ;;
esac
Run Code Online (Sandbox Code Playgroud)

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

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