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 run 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.
The typical way to run something when a specific user logs in a shell is with ~/.profile
(or equivalent depending on the underlying shell: ~/.bash_profile
, ~/.bash_login
, ~/.login
, etc). This executes just for the specific user and is in principle what I need. The problem is that those scripts do not run on "session logins" under desktop environments.
So there seems to be no obvious place to accomplish what I need.
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, since my script has nothing to do with graphics, it seems like the wrong thing to do.
Given this preamble, I would solve the problem as follows in principle.
- I would create a script in
~/etc/profile.d
that script should calls a second script if it exists, in the user folder. It could be one of the above mentioned files, or a new one entirely. I will use~/.profile
for simplicity. - For the specific user for which I would want to run my script, I would create an entry in
~/.profile
that calls the script I want to execute. This should run even if I log in through the desktop environment.
Is this the reasonable way to do it? Will it work?
Aucun commentaire:
Enregistrer un commentaire