Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - /etc/profile, excessive read only variable messages on login

On Ubuntu Linux, with Bash, I have /etc/profile set with read-only variables on login. Here's my /etc/profile ( my additions are toward the bottom of this file ):

# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return

# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
    if shopt -q progcomp && [ -r /etc/bash_completion ]; then
        # Source completion code.
        . /etc/bash_completion
    fi
fi
unset bash bmajor bminor

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

TZ='America/Kentucky/Louisville'; export TZ

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

if [ "$PS1" ]; then
if [ "$BASH" ]; then
PS1='\u@\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
  PS1='# '
else
  PS1='$ '
fi
fi
fi

 **# My Additions**

umask 077
shopt -s histappend
shopt -s histverify

export HISTFILE=~/.bash_history
export HISTFILESIZE=1000000000
export HISTSIZE=5000
export HISTCONTROL=""
export HISTIGNORE=""
export HISTTIMEFORMAT="%F %T"

readonly HISTFILE
readonly HISTFILESIZE
readonly HISTSIZE
readonly HISTCONTROL
readonly HISTIGNORE
readonly HISTTIMEFORMAT
readonly HISTCMD
readonly HOME
readonly PATH

echo -e "Subject: Login from $(/usr/bin/whoami) on $(/bin/hostname) at          $(/bin/date)\n\n$(/usr/bin/last -n 10 -F)\n" \
| /usr/sbin/ssmtp [email protected]

export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo "$$ $USER $(history    1)"|/usr/bin/logger -p user.alert -t shell.log'
readonly PROMPT_COMMAND

And here is the bash_completion file that is located in /etc/profile.d:

# Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return

# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
if shopt -q progcomp && [ -r /etc/bash_completion ]; then
    # Source completion code.
    . /etc/bash_completion
fi
fi
unset bash bmajor bminor

My problem is that when I login I am "flooded" with lots of bash messages before the prompt is delivered:

....
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: PATH: readonly variable
-bash: HISTFILE: readonly variable
-bash: HISTFILESIZE: readonly variable
-bash: HISTSIZE: readonly variable
-bash: HISTCONTROL: readonly variable
-bash: HISTIGNORE: readonly variable
-bash: HISTTIMEFORMAT: readonly variable
-bash: PROMPT_COMMAND: readonly variable

My first question is why is there so many PATH: readonly variable messages 15+ with full output? My second question is how can I get stop these messages from displaying on login.

Thanks in advance for any help!

like image 704
jonschipp Avatar asked Jun 28 '12 15:06

jonschipp


People also ask

What is Tmout readonly variable?

TMOUT is an environmental setting that determines the timeout of a shell in seconds. TMOUT=n - Sets the shell timeout to n seconds. A setting of TMOUT=0 disables timeout. readonly TMOUT- Sets the TMOUT environmental variable as readonly, preventing unwanted modification during run-time.

What is the ETC profile?

The /etc/profile contains Linux system wide environment and other startup scripts. Usually the default command line prompt is set in this file. It is used for all users logging in to the bash, ksh, or sh shells. This is usually where the PATH variable, user limits, and other settings are defined for users.

Where can I find etc environment?

You can see the programs using /etc/environment with grep -l pam_env /etc/pam. d/* . So /etc/environment is used for setting variables for programs which are usually not started from a shell.


1 Answers

Patient: "Doctor, it hurts when I do this."
Doctor: "Don't do that."

Don't set those variables as readonly.

The reason that you're getting those error messages is that those variables are being modified in files that execute after /etc/profile (e.g. ~/.bashrc).

like image 54
Dennis Williamson Avatar answered Sep 28 '22 16:09

Dennis Williamson