I am trying to write bash shell script in Ubuntu 11.10 Linux distro, that will get executed automatically on logging into the system. But I am not able to figure out that what to write in script that by it will get automatically executed on logging in.
I would highly recommend against using
/etc/profile.d/yourscript.sh if it produces output. When you use a non-interactive session, you will receive a
$TERM is not set message. This is noticeable when using the ssh protocol, like scp. Usually not a big deal, however, Veeam doesn't like it and will throw a warning. I know Veeam is not the topic here, but it's worth mentioning that not all applications will gracefully ignore the
$TERM is not set warning.
In short, if the script generates output, place it in the locations specified on the first line. However, if you're modifying the environment and your script doesn't generate output, then use the latter.
Just a data point since the question is tagged Ubuntu.
Under Ubuntu 20.04 and 22.04, the only option to autoload of a script/command at each login is (that worked for me) to add it in
As stated in the comments, adding it to
~/.profile doesn't seem to invoke the script. Adding it to
/etc/profile.d/ is not per login.