Does anybody know (of a resource listing) what scripts are run automatically, and when, from the moment I startup the computer until it's shutdown again.
I know several places where I can add scripts to run automatically, but I’ve never been able to figure out a more-or-less complete list.
For example, I know these:
~/.profile
is executed on login- I can use
crontab -e
to add scripts that will trigger on certain times and/or dates
But I can't figure out where to put scripts so that they'll be executed
- after boot, before X is initialized
- after the X (or other graphical shell) is initialized, but before anyone's logged in
- after logging in on an X session
- before/after fast user switching
- before logging out of an X session
- before shutdown on the X shell
- after shutdown of X, before system halt
- after login/before logout via tty-1..6
- after login/before logout via SSH
Is there such a list? If not, can we assemble one here?
Best Answer
For Ubuntu Linux we have the solution as:
For after boot, before X is initialized: Ubuntu starts X-Windows from GDM (those using the ubuntu-desktop) or from KDM (those using kubuntu-desktop)
To run a script prior to GDM/KDM, you have to write your own upstart script. For this, you can read Upstart Cookbook.
After user switching: You have to add the script in the
~/.bashrc
file.After Login in via tty: You have to add the script in the
~/.bash_profile
file.After Login using ssh but not while local login using tty: In this case also you have to add the script in the same
~/.bash_profile
file but in this case, test for the presence of theSSH_CONNECTION
environment variable, and only run the commands if you find it exists.Before Logging out via tty: You have to add the script in the
~/.bash_logout
file.Before Logging out via ssh: You have to add the script in the
~/.bash_logout
file, but in this case also , test for the presence of theSSH_CONNECTION
environment variable, and only run the commands if you find it exists. In the file you have to add the lineif [[ -n $SSH_CONNECTION ]]