LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2010, 03:55 PM   #1
bmn
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 0
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.
 
Old 07-30-2010, 04:05 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
Old 07-30-2010, 04:21 PM   #3
bmn
LQ Newbie
 
Registered: May 2009
Posts: 15

Original Poster
Rep: Reputation: 0
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!

Last edited by bmn; 07-30-2010 at 04:37 PM.
 
Old 07-30-2010, 04:22 PM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 5.4, Mac OS 10.4 (tiger)
Posts: 1,005

Rep: Reputation: 79
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.
 
Old 07-30-2010, 04:29 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I Run Login Scripts on OpenBSD 4.4? intermentals *BSD 6 02-01-2010 09:48 PM
[SSH]Which login scripts are run? jamesstanley Linux - Server 3 11-17-2007 07:24 AM
Where to run scripts automatically on login/logout hilltop*Tech Linux - General 2 02-06-2004 11:59 AM
Linux Login Scripts te_conway Linux - Networking 3 11-29-2002 05:06 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration