3

I need to run a bash script each time a Debian-esque thick client logs off, shuts down, or restarts. Outside of that, it can be any distro, desktop environment, window manager, or otherwise (preferably not Unity or Gnome 3; these are older machines), so long as it can do what I need.

I have already tried Lubuntu 12.04, without any luck.

Beefy_Swain
  • 431
  • 1
  • 4
  • 14

1 Answers1

4

You need to look into run levels, and how upstart ties in with them. This page explains a lot about two of the three stages you are interested in, shutdown and reboot, log off should also just be a simple hook.

NickW
  • 1,069
  • 5
  • 6
  • _"log off should also just be a simple hook"_ can you expand on that? What do you mean hook, exactly? I knew about run levels relating to shutdown and reboot, but I did not think that logging off was a different run level. – Beefy_Swain Jun 11 '13 at 15:33
  • 1
    Sorry, I was trying to state that it wasn't necessarily a change in run levels, you might be able to trigger off an event from a job stopping.. or from a custom triggered upstart instance for your user : http://upstart.ubuntu.com/cookbook/#upstart-user-sessions-spec – NickW Jun 11 '13 at 15:45
  • I see. If I trigger from an event stopping, how would my script be guaranteed to execute before it gets stopped? – Beefy_Swain Jun 11 '13 at 15:51
  • 1
    If you use the Method Event, you can give your script parameters, as they say on that page: "`The caller waits for the work to be done, and if problems were encountered, it expects to be informed of this fact.`". – NickW Jun 11 '13 at 15:55
  • Alright, Thanks. If I have more questions I'll post a second question, as im getting away from the original. – Beefy_Swain Jun 11 '13 at 15:57
  • 1
    Yeah, it's a seriously large concept, which is why I really didn't try to get into too much detail :) – NickW Jun 11 '13 at 15:58