LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ShellScrtips that run at Different System/User Level Events (https://www.linuxquestions.org/questions/linux-newbie-8/shellscrtips-that-run-at-different-system-user-level-events-725955/)

Hi_This_is_Dev 05-14-2009 09:25 AM

ShellScrtips that run at Different System/User Level Events
 
Hi All,


I want to run certain ShellScrpts whenever:

a user logs in, be it from Graphical Interface that is X, or from Virtual Console;

a user logs out;

a user restarts system;

a user shuts down system.


I am using Red Hat Enterprise Linux 5 and GNOME Desktop Environment.

Wherein can I make such configurations?


Thanks in advance!

Dev.

PTrenholme 05-14-2009 10:13 AM

Look in /etc/rc.d/rc<run_level>.d/ and /etc/init.d/, paying close attention to /etc/rc.d/rc.local

Generally, scripts (usually in /etc/init.d) symlinked from /etc/rc.d/rc<run_level>.d with namse starting with K are executed when the system boots to that run level, and, if they start with an S, the script is called when therun level is exited. The rc.local script is run at the end of the boot process. For users, there is .bashrc to be executed when bash is started, and the Autorun directories in various .<Display_Manager> directories which are run when the user logs in to a specific display manager.

chrism01 05-14-2009 07:11 PM

Those will work for restart/shutdown.
For login you could look at /etc/profile.
For logout I'm not sure; there's .bash_logout, but that's for each shell instance.
You could look at this: http://linux.derkeiler.com/Mailing-L...-08/2313.html; a solution for KDE, might be an equiv for Gnome as well.

Hi_This_is_Dev 05-15-2009 06:53 AM

I have already tired /etc/profile and it really serves the purpose of running a script when any user logs in.

It eliminates the time-consuming task of modifies each user's .bash_profile file.

Well, now let's take: .bash_logout file. I can make use of it in a similar fashion but again I have to modify each user's .bash_logout file.

Is there any way to do it on a "system-wide" level?

Quote:

Originally Posted by chrism01 (Post 3541208)
Those will work for restart/shutdown.
For login you could look at /etc/profile.
For logout I'm not sure; there's .bash_logout, but that's for each shell instance.
You could look at this: http://linux.derkeiler.com/Mailing-L...-08/2313.html; a solution for KDE, might be an equiv for Gnome as well.



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