LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How does linux know which scripts to run at login? (https://www.linuxquestions.org/questions/linux-newbie-8/how-does-linux-know-which-scripts-to-run-at-login-823104/)

bmn 07-30-2010 02:55 PM

How does linux know which scripts to run at login?
 
for example at login, Linux each time runs .bash_profile, is there a certain place where I can set which scripts to run? Or is this dependent of the distro? I only use command line btw.

druuna 07-30-2010 03:05 PM

Hi,

This depends a bit on the shell that is started (bash/ksh/tcsh/etc) and how it is started.

If you are talking about bash (most distro's use this as default): There are several files that bash (tries to) start: /etc/profile, ~/.bash_profile, ~/.bash_login and ~/.profile (in that order)

If you log out the following file is started: ~/.bash_logout (if present).

One or more of these files are probably present on your box and you can add stuff to it if you want to.

The above mentioned files are started when bash is started as an interactive login shell (not always the case).

If you want the complete story I would suggest reading the INVOCATION part of the bash manual (man bash).

Hope this clears things up a bit.

bmn 07-30-2010 03:21 PM

I get it now, if I want to execute scripts I have to put them there

/etc/profile is for everyone that logs in bash
and the other ones each user can customize, thanks!

r3sistance 07-30-2010 03:22 PM

firstly and most easily there is what drunna has said above.

Secondly, You can run linux service scripts by placing them in the related run level directories, I believe it is /etc/rcX.d/ where X is the run level. the script to start it must with an S and two numbers (for priority/ordering, most would default to 99 for non essential services). Starting the name with a K will kill the process at that run level which can be handy. I believe this is all right, but these things generally relate to services which require even more knowledge of what you are doing and creating script files to handle the service. From memory what appears in /etc/rcX.d/ are only soft links to scripts in /etc/init.d/

Thirdly there is the crontab that allows you to run scripts at certain times, it can be set to re-run a script every few seconds if I remember correctly or potentially once a month kind of thing...

There maybe other ways but none I can recall off of my head.

druuna 07-30-2010 03:29 PM

Hi,

r3sistance has a point, the main difference between adding stuff to the bash files (my reply) and using run levels scripts (r3sistance second point) is that run level scripts are executed (one time) when you start (and stop) your machine. Bash script are used when a user logs in (or out).

I'm not sure if r3sistance's third point (crontab) is what you are looking for, but worth mentioning.

Hope this clears things up a bit.


All times are GMT -5. The time now is 08:12 AM.