Shell scripts cannot find my command in PATH

I put a custom command (shell script) in /usr/local/scripts/

.

To see the commands from /usr/local/scripts

, I set the PATH using the following methods:

  • sudo visudo

    Defaults  secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/scripts"
    
          

  • sudo nano /etc/profile

    PATH = "$ PATH: / usr / local / scripts" export PATH

  • sudo nano /etc/login.defs

    ENV_SUPATH PATH = / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / local / scripts ENV_PATH PATH = / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / local / games: / usr / games: / usr / local / scripts

  • sudo nano /root/.bashrc

    PATH = "$ PATH: / usr / local / scripts" export PATH

  • sudo nano /etc/environment

    PATH = "/ usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / sbin: / bin: / usr / games: / usr / local / games: / usr / local / scripts "

And it works in most cases, but ...

I have two script that in their code calls the script from /usr/local/scripts/

and it cannot find my script!

The first is /etc/network/if-up.d/sendip

, which runs as root when initializing the network stack.

And the second one /usr/local/scripts/notif-login

, which runs as root from pam

on /etc/pam.d/sshd

:

session optional pam_exec.so /usr/local/scripts/notif-login

      

If I run as a script from my terminal shell, another user, with sudo, no sudo, after su, or login with root, it works correctly. But when it is started by the system (first when initializing the network, and secondly via SSH) both did not run scripts from /usr/local/scripts

.

Is there some other place where I should set the path?

+3


source to share


1 answer


Bash / sh will not read /etc/profile

for "non-interactive shells" such as shells from which scripts are run. I'm not sure which distribution you are using, but you should just add it to the definition /etc/environment

PATH

. Ob Ubuntu, for example:

Edit:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

      

To:



PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/scripts"

      

Edit

This should work under Raspbian; it works under Debian. If this is not the case, you may need to simply change the path at the beginning of one of your scripts. None of the regular startup files will execute for a non-interactive session in the Bash section. Also try to output $SHELL

and make sure the script runs under the shell you think.

+1


source







All Articles