我经常挂起笔记本电脑(pm-suspend),有时又经常挂起台式机(pm-suspend-hybrid)。我正在使用最新的Ubuntu(13.10,saucy)。
当我进入暂停状态或退出暂停状态后,是否可以运行命令?我想终止所有打开的ssh连接并停止offlineimap,因为这些连接的超时通常很烦人。有想法吗?
我经常挂起笔记本电脑(pm-suspend),有时又经常挂起台式机(pm-suspend-hybrid)。我正在使用最新的Ubuntu(13.10,saucy)。
当我进入暂停状态或退出暂停状态后,是否可以运行命令?我想终止所有打开的ssh连接并停止offlineimap,因为这些连接的超时通常很烦人。有想法吗?
Answers:
从联机帮助页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连接。