Solved Scripts can't be logged in 14 to run automatically

The same script is placed in the PS1_DIY.sh as /etc/profile.d/

Runs automatically and succeeds when logging in in 13.
In 14 it doesn't run automatically, but it can run manually and succeed.

When I moved the script in 13


1722849091020.png



Here are the results
1722849315747.png


This means that the /etc/profile.d/PS1_DIY.sh of 13 is in the correct location. Just place and don't need to load.

But in 14 the same position really does not work.



If the script is loaded in ~/.profile at 14, it can run automatically on login.
However, the script is loaded in /etc/pofile in 14 and does not run automatically on login.



1722849204636.png
 
Please don't post pictures of text.

What shell does root have?
 
The default is SH
But I changed it to bash, and the script was based on bash.

pkg install -y bash bash-completion
chsh -s /usr/local/bin/bash

The root shells of 13 and 14 are both bash
 
TL;DR

bash(1) doesn't execute /etc/profile and thus nothing from /etc/profile.d/ either.

Code:
       When bash is invoked as an interactive login shell, or as a non-
       interactive shell with the --login option, it first reads and executes
       commands from the file /usr/local/etc/profile, if that file exists.
       After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
       and ~/.profile, in that order, and reads and executes commands from the
       first one that exists and is readable.  The --noprofile option may be
       used when the shell is started to inhibit this behavior.
bash(1)

Code:
   Invocation
     If no arguments are present and if the standard input of the shell is
     connected to a terminal (or if the -i option is set), the shell is
     considered an interactive shell.  An interactive shell generally prompts
     before each command and handles programming and command errors
     differently (as described below).  When first starting, the shell
     inspects argument 0, and if it begins with a dash (‘-’), the shell is
     also considered a login shell.  This is normally done automatically by
     the system when the user first logs in.  A login shell first reads
     commands from the files /etc/profile and then .profile in a user's home
     directory, if they exist.  If the environment variable ENV is set on
     entry to a shell, or is set in the .profile of a login shell, the shell
     then subjects its value to parameter expansion and arithmetic expansion
     and reads commands from the named file.  Therefore, a user should place
     commands that are to be executed only at login time in the .profile file,
     and commands that are executed for every shell inside the ENV file.  The
     user can set the ENV variable to some file by placing the following line
     in the file .profile in the home directory, substituting for .shrc the
     filename desired:

           ENV=$HOME/.shrc; export ENV

     The first non-option argument specified on the command line will be
     treated as the name of a file from which to read commands (a shell
     script), and the remaining arguments are set as the positional parameters
     of the shell ($1, $2, etc.).  Otherwise, the shell reads commands from
     its standard input.

     Unlike older versions of sh the ENV script is only sourced on invocation
     of interactive shells.  This closes a well-known, and sometimes easily
     exploitable security hole related to poorly thought out ENV scripts.
sh(1)
 
and PS1_DIY.sh script under /usr/local/etc/profile.d
Don't need to do this. /etc/profile will execute them from /etc/profile.d. So if you copy /etc/profile to /usr/local/etc/profile it will already work.

Code:
# Load each .sh file in /etc/profile.d/, then /usr/local/etc/profile,
# then each .sh file in /usr/local/etc/profile.d/.
_loaded=${_loaded:-/etc/profile}
export _loaded
for _dir in /etc /usr/local/etc ; do
        for _file in "${_dir}"/profile "${_dir}"/profile.d/*.sh ; do
                if [ -f "${_file}" ] ; then
                        case :${_loaded}: in
                        *:"${_file}":*)
                                ;;
                        *)
                                _loaded="${_loaded:+${_loaded}:}${_file}"
                                . "${_file}"
                                ;;
                        esac
                fi
        done
done

Things might get executed twice though, be aware of this.

Note that it's generally a bad idea to set a non-base shell for root. You can run into serious problems if you're not careful when doing a major version upgrade, especially if you do this remotely.
 
Don't need to do this. /etc/profile will execute them from /etc/profile.d. So if you copy /etc/profile to /usr/local/etc/profile it will already work.

Code:
# Load each .sh file in /etc/profile.d/, then /usr/local/etc/profile,
# then each .sh file in /usr/local/etc/profile.d/.
_loaded=${_loaded:-/etc/profile}
export _loaded
for _dir in /etc /usr/local/etc ; do
        for _file in "${_dir}"/profile "${_dir}"/profile.d/*.sh ; do
                if [ -f "${_file}" ] ; then
                        case :${_loaded}: in
                        *:"${_file}":*)
                                ;;
                        *)
                                _loaded="${_loaded:+${_loaded}:}${_file}"
                                . "${_file}"
                                ;;
                        esac
                fi
        done
done

Things might get executed twice though, be aware of this.

Note that it's generally a bad idea to set a non-base shell for root. You can run into serious problems if you're not careful when doing a major version upgrade, especially if you do this remotely.
Yes, using a non-default shell is risky.

It is possible that the root shell was changed to sh due to the snapshot rollback, so that the script did not take effect. Misunderstandings were created

Thank.
 
Things might get executed twice though, be aware of this.
That's what I tried to avoid.

/usr/local/etc/profile:
#
# bash doesnt read /etc/profile, but this here
# shell also reads this here AND /etc/profile and sets $_loaded
#
case :${_loaded}: in
*:/usr/local/etc/profile:*)
;;
*)
[ -r /etc/profile ] && . /etc/profile
esac[/code]
 
Back
Top