profile.d sh.local problem

General support questions
Post Reply
ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

profile.d sh.local problem

Post by ron7000 » 2019/09/11 18:16:15

the file /etc/profile.d/sh.local that comes with the CentOS install.

The comment in it has add any required envvar overrides to this file, it is sourced from /etc/profile

So I figure that's a good place to put my aliases and modifications to PATH and LD_LIBRARY_PATH?

Problem is it sort of does not work. First it seems when this file is edited that a reboot was need for it to go into effect. But if I am doing systemctl set-default multi-user.target then when I log in the stuff that's in sh.local is in effect. But when I go to runlevel 5 graphical-target then nothing in sh.local is in effect.

for a while I have known sh.local not to work, and I've been making an /etc/profile.d/local.sh file instead.. by coincidence actually. My understanding was any *.sh file within /etc/profile.d/ would be sourced for a bash shell?
But I eventually saw sh.local and thought I should do it this way instead but it seems to not work.
What's the deal?

I am now manually linking a local.sh and pointing it to sh.local within /etc/profile.d.
What's the best way to deal with this kind of thing... needing to set global environment variables like PATH and LD_LIBRARY_PATH that go into effect for any user that logs in?

Also, I install intel_mpi and I need for each user when they log in to source /opt/intel/bin/compilervars.sh. I always made that happen from sh.local or local.sh, is there a better way?

User avatar
jlehtone
Posts: 2308
Joined: 2007/12/11 08:17:33
Location: Finland

Re: profile.d sh.local problem

Post by jlehtone » 2019/09/11 21:06:36

The /etc/profile

Code: Select all

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
explicitly sources /etc/profile.d/sh.local after any /etc/profile.d/*.sh.

With your link you essentially source the same file twice.

man bash wrote:/etc/profile
The systemwide initialization file, executed for login shells
Login shell. Changing runlevel is not the key. Logout and then login is.


Editing PATH: Add *.sh-file(s) to /etc/profile.d/ that contain:

Code: Select all

pathmunge /mybindir after
(The function pathmunge is defined in /etc/profile.)
Name of file affects order of the PATH-list if /etc/profile.d/* add many entries.

Adding a file is immune to package updates that could modify /etc/profile.d/sh.local


Editing LD_LIBRARY_PATH:
* System libraries one can configure in /etc/ld.so.conf.d/*.conf See man ldconfig (I hope you do use rpm's.)

If a user profile can modify LD_LIBRARY_PATH on login, then it could made to point to hacked security libs instead of trusted and escalate intrusion. There are protections against that. Could affect what you get into LD_LIBRARY_PATH.


Check package environment-modules. That is an another way to "source vars", but with more control.

ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

Re: profile.d sh.local problem

Post by ron7000 » 2019/09/12 20:09:56

what i was saying was
  • centos 7.6 installed as server with gui, boots to runlevel 5 graphical.target, sh.local does NOT work
  • i recognized when I had systemctl set-default multi-user.target and booted to runlevel 3 that then sh.local was in effect.
  • from runlevel 3 doing systemctl isolate graphical.target and then log in (as root) then sh.local doesn't work.
is what's happening correct?

fwiw I was a Suse/SLES user, always managed everything there from /etc/bash.bashrc.local. The system file there that the admin should not modify was /etc/bash.bashrc and at the bottom of that file it sourced bash.bashrc.local. I was hoping to preserve that mentality. in rhel/cent that all works fine if I do /etc/profile.d/anything.sh. But seeing "sh.local" and that not working as expected is spooling up my ocd.

tunk
Posts: 585
Joined: 2017/02/22 15:08:17

Re: profile.d sh.local problem

Post by tunk » 2019/09/13 13:12:19

Is this any help? It's for ubuntu, so it may/may not apply to CentOS:
https://askubuntu.com/questions/438150/ ... ng-ignored

ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

Re: profile.d sh.local problem

Post by ron7000 » 2019/09/13 14:18:16

sort of, thanks.

in Centos/RHEL 7.6 in /etc/profile at the bottom it has

Code: Select all

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
        
                                           echo $i
                                           
            . "$i"
        else
        
                                           echo $i
                                           
            . "$i" >/dev/null
        fi
    fi
done
so this works for runlevel 3 {multi-user.target} fine... have basic login prompt on your screen no graphics, log in and my echo statements print out and whatever is in sh.local goes in effect.
in runlevel 5 {graphical.target} nothing

gotta believe this code is happening whenever a terminal window is opened in runlevel 5 because if i have a link local.sh->sh.local then things happen. But only if there is a something.sh present.
The sh.local file... no workie in runlevel 5 :(

ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

Re: profile.d sh.local problem

Post by ron7000 » 2019/09/13 14:27:39

so now i'm curious and playing around in runlevel 3 editing /etc/profile

Code: Select all

for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
 
 echo ron ${-#*i}
 
        if [ "${-#*i}" != "$-" ]; then                                            
            . "$i"
        else                                          
            . "$i" >/dev/null
        fi
    fi
done
so for each .sh file under /etc/profile.d/ my echo statement here gives mBH

what does if [ "${-#*i}" != "$-" ] mean?

ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

Re: profile.d sh.local problem

Post by ron7000 » 2019/09/13 14:39:15

so i think i figured it out.

seems like things do work but not for aliases

in just sh.local i can do a simple export PATH=$PATH:/ron and that works fine in runlevel 5.

I am also doing some things like alias c='clear' in sh.local and those aliases don't work in runlevel 5 but they do in runlevel 3.

Tried doing export alias c='clear' but that doesn't work.

anyone know why the aliases get killed from sh.local ?

and where should I put some global aliases like these?

Code: Select all

unalias ls
alias l='ls -FC'
alias c='clear'

ron7000
Posts: 109
Joined: 2019/01/15 20:00:28

Re: profile.d sh.local problem

Post by ron7000 » 2019/09/13 14:49:13

still reading?

so in /etc/profile.d/sh.local i am now only doing 2 things... export PATH=$PATH:/whatever and export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/whatever. This works fine, in runlevel 5, do not need a local.sh link or separate file otherwise u will get things duplicated for PATH.

Decided to do a /etc/profile.d/aliases.sh and just put preferred global aliases, and only those, in there.

Code: Select all

unalias rm 2>/dev/null
unalias cp 2?/dev/null
unalias ls 2>/dev/null

alias l='ls -FC'
alias c='clear'
Basically I only want to do 2 (or 3) things: append PATH, and LD_LIBRARY_PATH, and do some simple aliases. Would be convenient if everything could happen in just sh.local but it seems the alias does not preserve into runlevel 5 from sh.local.

curious as to why that happens with "sh.local" but not with "something.sh" for "alias".

Post Reply

Return to “CentOS 7 - General Support”