Search code examples
pythonbashsshpathfabric

How do I get the correct $PATHs for remote Python Fabric Access?


I am writing a python program that establishes a ssh connection to a server. For this I am using fabric (fabfile.org).

When I connect to the server via ssh in a terminal, I get my $PATHs set. When I connect to the server via fabric in my python program, $PATHs are missing...

  1. Where does bash load the $PATHs when I connect via terminal?
  2. How do I manage that fabric does the same?

Thanks in advance!

edit: this is what I get, when I run echo -e ${PATH//:/\\n}:

SSH via Terminal:

/home/myusername/bin
/home/myusername/.local/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/mpich-3.4.2-npjoxvgsi2nthnyp5shm42is7wzxdll7/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/libfabric-1.12.1-mzleboxdvvcdtdwg7qg6wf54xwvsmyoz/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/rdma-core-34.0-rf4h4kiatax6su3acacuxu33vxpq5mh4/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/libnl-3.3.0-ih7pa4rn4nuvraaomc4c2ou6f2opyyve/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/hwloc-2.4.1-djw5rieilo4sypmpsew5rudmesqaw7mp/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/ncurses-6.2-fsd347mkpmp6iezvqzfrn4mqj4wi42be/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/libxml2-2.9.10-rjlorqqgjthe6pheei3mbug73tqdjy74/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/xz-5.2.5-oxdrliw6ak4a54igymkcim5l7w2gcmx2/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-11.1.0/libiconv-1.16-dqvkzxma2htfkms66pdqtntndl7gqpzf/bin
/opt/spack/20210902/opt/spack/linux-ubuntu18.04-x86_64/gcc-7.5.0/gcc-11.1.0-5ikoznknx7aaqakigpo7nriui22lrle5/bin
/opt/vampir/9.3.0/bin
/opt/matlab/R2016a/bin
/opt/ddt/5.0.1/bin
/opt/spack/current/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

SSH via Fabric:

/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin

Solution

  • I found the solution: I got to run source /etc/profile with fabric in order to get my correct PATHs.

    Found out by reading: https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files