Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer
    
"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. – Dudemcman 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 : 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? – Dudemcman 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
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

You must log in to answer this question.

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