I am trying to run a script automatically under the following circumstances:
- A specific user logs in.
- Independently of how the user is logging in: be it through the shell, a desktop environment session, or something else.
To accomplish this and out of curiosity I am studying initialization scripts in general at the different stages of the booting process. My specific question seems to require a lot of work given how I am understanding those processes. I am wondering if there's a better, simple way. Let me explain how I understand things:
The typical way to run something when the computer boots, is by using
/etc/init.d; this is far from what I need since it executes prior to log in;
The typical way to run something when log in takes place, is by using
/etc/profile or more appropriately a script in
/etc/profile.d; this is not what I need because every user will load the script I want to run and it won't execute by default under a DE.
A typical way to run something when a specific user logs in a shell is with
~/.profile (or equivalent depending on the underlying shell:
~/.login, etc). This executes just for the specific user and is in principle what I need. The problem is that as with
/etc/profile. those scripts do not run on "session logins" under desktop environments.
One can of course use the facilities of a specific desktop environment to run a script. But that is not portable across distributions, it is not what I want. For example in Ubuntu one can create a
.desktop file and place it in
~/.config/autostart. But as soon as one wants to try a different distro the solution breaks. Also, I read here: http://www.linuxmisc.com/11-unix-aix/6118cce17a587c8d.htm about the unsafety of runing etc/profile under DE, so that is not a great solution.
So there seems to be no obvious place to accomplish what I need. The questions are:
- given that the users are common to all login forms, is there something executing in common between the shell login and the DE. Where/what is that script/command?
- If the answer to 1 is nowhere, I would ask: since it seems obvious we would like a place/script where we can execute tasks that are independent of the login front end, why does it not exist?