I suspend my laptop (pm-suspend) often and sometimes my desktop (pm-suspend-hybrid) fairly often. I am using the latest ubuntu (13.10, saucy).

Is there a way I could run a command when I go into suspend or immediately after coming out of suspend? I'd like to kill any open output ssh connections and stop offlineimap, since the timeout for those tends to be annoying. Ideas?

1 Answer 1


From manpage 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.

Thus you could simply put a shell-script like this:


case "$1" in
    actions to
    on suspend
    or hibernate
    other actions
    to trigger
    on resume

into e.g. 99-myhooks.sh and make it executable.

BTW, you can kill stale SSH-connections by entering Enter~.Enter in the SSH session.

  • This is obviously pre-systemd
    – MountainX
    Dec 23, 2018 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .