0

Is it possible to have a script invoked when my PC decides to sleep or when it is put to sleep manually.

What I am trying to do is to have a script that will take down my VPN and the SSH key, when sleep happens. I don't use hibernate these days, otherwise I would have been interested in that event as well.

Is there some sort of setup that can be done to handle a dbus event? Does the power management fire off such events?

Any pointers will be of great help. I would prefer to do it in the normal user land; i.e no root privileges. I am more in bed with KDE than any other DE; but I wouldn't mind a more generic solution that I can take along to any other DE.

CodeMedic
  • 130

1 Answers1

0

refer pm-action man page: http://manpages.ubuntu.com/manpages/trusty/man8/pm-action.8.html, and refer the FILES section.

Any executable script put in the directory /etc/pm/sleep.d/ will be invoked before the suspend happens. Putting a file here will require sudo.

Bhavin Doshi
  • 2,466
  • Thanks; would it be fair to assume that these scripts will be executed as root ( or some other system user) who will not have access to the logged in user's dbus and/or ssh-agent. If that is true, is there a clean way to get around it ( in a clean manner ). – CodeMedic Mar 10 '15 at 22:33
  • I am not sure if the following is clean or hacky, but it is "a" way: http://askubuntu.com/questions/521620/prevent-machine-from-sleeping-when-ssh-connections-are-on – Bhavin Doshi Mar 11 '15 at 22:45