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


9

我经常挂起笔记本电脑(pm-suspend),有时又经常挂起台式机(pm-suspend-hybrid)。我正在使用最新的Ubuntu(13.10,saucy)。

当我进入暂停状态或退出暂停状态后,是否可以运行命令?我想终止所有打开的ssh连接并停止offlineimap,因为这些连接的超时通常很烦人。有想法吗?

Answers:


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.

因此,您可以简单地输入如下的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~.EnterSSH会话来终止陈旧的SSH连接。


这显然是预先systemd
MountainX
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.