1

This problem drives me nuts. It is working in all my RHEL systems, but on Ubuntu20LTS I cannot get it to work properly.

The configuration:

The environment-modules are loaded via a script in "/etc/profile.d" for all users when they open a terminal/konsole. The module "aliases" defines aliases for all our projects and all users shall see those aliases in their environment. As I learned, the terminal/konsole will open "interactive non-login-shells". I our configuration, the ".bashrc" is sourced when the terminal/konsole is opened.

What is expected and working on RHEL, but not working on Ubuntu20LTS:

Open terminal or konsole --> modules are loaded (via script in “etc/profile.d/…”) --> “alias” shows all defined aliases from module “aliases” (see the ".bashrc" content at the end of this post) :

I am .bashrc and was loaded!
[INFO:] $MODULEPATH=/icd/cfg/modules:

Currently Loaded Modulefiles:

  1. aliases 2) common 3) aliases_ue

[userXY@host:~]

alias

alias ATIC183='cd $ICD_PROJ/ATIC183; source $ICD_CFG/env/proj_setup/start_proj.sh' alias FFT='cd $ICD_PROJ/monarch; source $ICD_CFG/env/proj_setup/start_proj.sh' alias HXLR0='cd $ICD_PROJ/HXLR0; source $ICD_CFG/env/proj_setup/start_proj.sh'

What is experienced on Ubuntu20LTS:

Open terminal --> modules are loaded --> “alias” does NOT show the defined aliases, only the one definition from ".bashrc":

I am .bashrc and was loaded!
[INFO:] $MODULEPATH=/icd/cfg/modules:

Currently Loaded Modulefiles:

  1. aliases 2) common 3) aliases_ue

[userXY@host:~]

alias

alias ll='ls -al'

What has been tested in addition and does NOT work:

Open terminal --> reload module via “module load aliases” --> “alias” does NOT show the defined aliases

Open terminal --> “su userXY” --> modules are loaded --> “alias” does NOT show the defined aliases

# su userXY
Password: 
I am .bashrc and was loaded!
[INFO:] $MODULEPATH=/icd/cfg/modules:

Currently Loaded Modulefiles:

  1. aliases 2) common 3) aliases_ue

[userXY@host:~]

alias

alias ll='ls -al'

Open terminal --> “bash -l” --> modules are loaded --> “alias” does NOT show the defined aliases, but other aliases are loaded in addition

Open terminal --> “su userXY” --> modules are loaded --> “bash -l” --> alias” does NOT show the defined aliases, but other aliases are loaded in addition

# bash -l
I am .bashrc and was loaded!
[INFO:] $MODULEPATH=/icd/cfg/modules:

Currently Loaded Modulefiles:

  1. aliases 2) common 3) aliases_ue

[userXY@host:~]

alias

alias ll='ls -al' alias pat='puppet agent -t' alias su2='sudo su -'

Open terminal --> “sudo su userXY” --> NO modules are loaded

# sudo su userXY
ERROR: No module path defined
ERROR: No module path defined
I am .bashrc and was loaded!
[INFO:] $MODULEPATH=

No Modulefiles Currently Loaded.

What is working to get the aliases:

Open terminal --> “sudo su userXY” --> NO modules are loaded --> “bash -l” --> alias shows all defined aliases

Open terminal --> ssh localhost --> modules are loaded --> alias shows all defined aliases

# sudo su userXY
ERROR: No module path defined
ERROR: No module path defined
I am .bashrc and was loaded!
[INFO:] $MODULEPATH=

No Modulefiles Currently Loaded. [userXY@host:~]

bash -l

I am .bashrc and was loaded! [INFO:] $MODULEPATH=/icd/cfg/modules:

Currently Loaded Modulefiles:

  1. aliases 2) common 3) aliases_ue

[userXY@host:~]

alias

alias ATIC183='cd $ICD_PROJ/ATIC183; source $ICD_CFG/env/proj_setup/start_proj.sh' alias FFT='cd $ICD_PROJ/monarch; source $ICD_CFG/env/proj_setup/start_proj.sh' alias HXLR0='cd $ICD_PROJ/HXLR0; source $ICD_CFG/env/proj_setup/start_proj.sh'

Its seems it has to do with the login and non-login shells. But I cannot find out why the aliases (which are defined by the loaded modules) are overwritten/deleted in the one scenario, but are available in the other scenario.

Those are config-files in my $HOME:

.bash_aliases --> not existent

.profile --> not existent

.login --> not existent

.cshrc --> not existent

.bashrc

#cat .bashrc

case "$0" in -sh|sh|/sh) modules_shell=sh ;; -ksh|ksh|/ksh) modules_shell=ksh ;; -zsh|zsh|/zsh) modules_shell=zsh ;; -bash|bash|/bash) modules_shell=bash ;; esac module() { eval /usr/bin/tclsh8.6 /usr/lib/x86_64-linux-gnu/modulecmd.tcl $modules_shell $*; }

.bashrc

Source global definitions

if [ -f /etc/bashrc ]; then . /etc/bashrc fi

if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi

Uncomment the following line if you don't like systemctl's auto-paging feature:

export SYSTEMD_PAGER=

User specific aliases and functions

export SVN_EDITOR=vi

#colorized shell prompt export PS1='[[\033[1;31m]\u@[\033[1;34m]\h:[\033[0;32m]\w[\033[0m]]\n# '

load aliases

module load aliases_ue

#disable beep xset b off

alias ll="ls -al" echo "I am .bashrc and was loaded!" echo -e "[INFO:] $MODULEPATH=$MODULEPATH\n" module list

.bash_profile

# cat .bash_profile
# .bash_profile

Get the aliases and functions

if [ -f ~/.bashrc ]; then . ~/.bashrc fi

User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

.kshrc

# cat .kshrc 
# .kshrc

Source global definitions

if [ -f /etc/kshrc ]; then . /etc/kshrc fi

use emacs editing mode by default

set -o emacs

User specific aliases and functions

Any hint is very much appreciated !

HWe
  • 29

2 Answers2

0

My issue is resolved by switching from "environment-modules" to the alternative "Lmod" modules implementation (which is the "modules" alternative I use on RHEL as well).

After purging "environment-modules" and installing "lmod" via apt, I followed this tutorial from the "Lmod" website: https://lmod.readthedocs.io/en/latest/030_installing.html#bash-under-ubuntu

It basically enables the interactive-non-login-shell (when opening a terminal/konsole) to load the *.sh files under "/etc/profile.d" by adding this to the "/etc/bash.bashrc":

if ! shopt -q login_shell; then
  if [ -d /etc/profile.d ]; then
    for i in /etc/profile.d/*.sh; do
      if [ -r $i ]; then
        . $i
      fi
    done
  fi
fi

With this setting, the modules and aliases are loaded directly when a terminal/konsole is opened.

HWe
  • 29
0

On Ubuntu and other Debian-like systems /etc/profile script is not taken into account by shell when it initializes in non-interactive mode. See https://askubuntu.com/a/247769 for a detailed overview of how bash initializes on such systems.

Once environment-modules is installed on your system, some extra steps should be performed to get the module shell function defined when bash shell is run in non-interactive mode.

Following code snippet has to be added to either your personal (~/.bashrc) or system-wide (/etc/bash.bashrc) bash initialization file:

# enable module command in non-interactive shells
if ! shopt -q login_shell; then
    . /usr/share/modules/init/bash
fi

You can refer to the Enable Modules in shells guidelines to setup module function in supported shells for their different execution modes (interactive or non-interactive).