Archive

Posts Tagged ‘sudo’

Lmod and Sudo: ‘module: command not found’

September 11th, 2015 No comments

Recently, I switched from Environment Modules to Lmod because of … reasons. I really like it so far but one thing annoyed me a bit. When executing sudo -s which is one of my usual workflows, my shell reports:

module: command not found

The reason is simple: sudo dumps most of the users environment with some exceptions, due to env_reset in /etc/sudoers, when spawning the new non-login shell. Specifically the last fact causes the trouble since Lmod is activated by sourcing the proper file on (login-)shell startup. In my case (following the Lmod docs) there is a soft link in /etc/profile.d pointing to /usr/share/lmod/lmod/init/profile.

My first attempts to modify the env_keep list in /etc/sudoers didn’t work, because the module command itself is set as a shell function which AFAIK cannot be handled by that list of kept variables.

from the shell environment:

BASH_FUNC_module%%=() { eval $($LMOD_CMD bash “$@”);
[ $? = 0 ] && eval $(${LMOD_SETTARG_CMD:-:} -s sh)

$ type module
module is a function
module ()
{
eval $($LMOD_CMD bash “$@”);
[ $? = 0 ] && eval $(${LMOD_SETTARG_CMD:-:} -s sh)
}

So I saw no other solution but adding the following code snippet to my /etc/bash.bashrc

if [ -z "$LMOD_CMD" ]; then
. /etc/profile.d/modules.sh
fi

This will test if there is a LMOD_CMD environment variable set. If not, it will source the proper file to activate Lmod.

Feel free to post if there are better solution! Cheerio!

sudo forgot /sbin

December 10th, 2012 No comments

I got confused by some APT messages today, saying it cannot find ldconfig. A little trial-and-error made me found my environment (PATH) has forgotten /sbin and other folks. Long story short, it turns out sudo did not source the environment correctly, leaving out root-depending paths. Adding the following line at the top of  /etc/sudoers will fix this:

Defaults        secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”

So long…

Categories: linux Tags: