Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to run a script when user logged out. My linux distribution is Pardus that uses KDE. How can I do this?

I've heard about "/.bash_logout" but I couldn't implement that. Where should I create the "/.bash_logout" file?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

I am assuming that you want this on a per-user basis for the following

There are a few different options, but first to clear up a misunderstanding, you mention "/.bash_logout", but everywhere I have seen suggests ~/.bash_logout.

The ~ is a short way to say "this user's home". So that would mean you need to make the .bash_logout file in /home/USERNAME/.bash_logout.

Another option is to use KDE's suggestion of: /home/USERNAME/.kde4/shutdown/. Add scripts there and make sure they are executable (chmod +x ~/.kde4/shutdown/scriptname.sh). If the folder doesn't exist, simply make it.

If you want this to happen for all users

Use /usr/shutdown/.

Note: I do not have KDE to test the KDE specifics for you.

share|improve this answer
    
/usr/kde/3.5/shutdown is ok for I wanted. Yes, it works thank you. I could add a new sh file into the shutdown and run. –  skoroglu Jul 10 '13 at 9:48
add comment

First of all, you can create a file in your home directory called .bash_logout.
Note the dot in front of it. This denotes configuration files and those are usually not listed when you type ls unless you add the -a option.

First check if your system supports this file. (e.g. it might not do anything if you do not run bash. You might be using an other shell, such as zsh, sh, pinosh, dc, ...

Testing this can be as simple as doing a vim ~/.bash_logout and adding a line echo This works! to the end of it. Log out from your text console and check if it echos a "This works!" to the screen. If you are using a graphical environment which closes a terminal when you log out from it then placing another command in the .bash_logout file might be more convenient. (E.g. the command touch bash_logout_last_tiggered. This will set the modification date of the file *bash_logout_last_tiggered* to time that the touch command ran).

Next read up on nohup. Basically when you log out from a shell each program which is still running will get a signal telling it to stop. This signal is called HUP (hangup). The name originates the time when people used phone lines to dial in to servers/ These connection sometimes dropped when there was noise on the line. YOu then got the choice of keeping programs running or doing a clean up. The choice made was to send all programs signal 1, SigHUP. The programs would then neatly clean up (e.g. a text editor would save its file and exit. A game would save and exit, etc etc).

You can either write a program and allow it it intercept the sighup, in which case you can choose to do noting. Or use the nohup wrapper to do this for you.

Examples:

cd /usr/src/linux ; make bzImage will start the compilation of a new kernel. This is something which can take a long time (typically hours in the 80486 era).

During all that time my terminal is busy, hopefully showing the successful compilation of a new kernel. I can not do anything else.

Now if I add an ampersand (&) to the command it will run in the background.
However it will still receive the sigHup when I log out.

The solution: **nohup** command_here **&**.
Notice both the nohup in front of the command and the ampersand at the end (which also means it will not receive input.


All of this assumes that you are running bash and that you do not want to trigger anything from the KDE windows manager. Something which I am sure is also possible (but which was not the question asked).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.