I want to run some commands every time a user of an ubuntu 9.10 machine logs out or shuts down. What is the best way to do this? Every user uses gnome if that helps.
migrated from stackoverflow.com Apr 5 '10 at 1:17
This question came from our site for professional and enthusiast programmers.
After some Googling I found How to run a script on logout? which says to add the script to $HOME/.bash_logout.
If that doesn't work, add
to /etc/gdm/PostSession/Default so it executes the logout script properly.
Seeing as before shutdown the user is logged off anyway, this should cover both bases.
If you are using KDE (I am using Ubuntu with kdm)
Open the appropriate file i.e.
Add a test command (create a file in my home directory)
Then I logged out, and back in again, and checked if the new file was created
Hmm..well if you google "linux run script on shutdown", the first result is a post on the Ubuntu forums with your answer:
chmod +x /etc/init.d/foo.sh
This will allow you execute the script as a program.
To have a script run at shutdown, use this technique:
sudo ln -s /etc/init.d/foo.sh /etc/rc0.d/K10rensa.sh sudo ln -s /etc/init.d/foo.sh /etc/rc6.d/K10rensa.sh
background on how this works: An introduction to run-levels.
As a sidenote, should I refrain from indulging people with answers when it is clear that they haven't even tried searching the Internet first (I'm new here..)?