通过 ssh 包括 .bash_profile

tur*_*too 4 ssh bashrc

我正在尝试编写一个脚本,它将:

  1. 将文件复制到服务器(我已经有一个copy.sh执行此任务的脚本)
  2. ssh 到那个服务器
  3. cd到我刚才复制的文件所在的目录
  4. make
  5. 将生成的二进制文件从make另一个位置复制到另一个位置。

我的脚本如下所示:

#!/usr/bin/bash
BUILDSERV=me@server
BUILDDIR=/me/directory

#run my script that copies the files
./copy.sh

#TARGET is also a var in copy.sh so I make sure it's set properly here
TARGET=root@final_dest:/usr/bin/my_bin

ssh $BUILDSERV "cd $BUILDDIR && make && scp ./my_bin $TARGET"
Run Code Online (Sandbox Code Playgroud)

问题是我想作为其一部分运行的程序make不在我的PATH. 我.bash_profile有一条export PATH=$PATH:/my/bin/线,但是bash_profile当我 ssh 进入时似乎没有被读取。

有没有办法更改我的 ssh 调用或脚本以使其读取我的 ssh 调用.bash_profile

cel*_*chk 5

以下应该工作:

ssh $BUILDSERV "source ~/.bash_profile && cd $BUILDDIR && make && scp ./my_bin $TARGET"
Run Code Online (Sandbox Code Playgroud)

所述source外壳内置读取文件和执行相同的外壳中的命令(不同于简单地调用脚本,这将调用一个单独的壳)。

当作为登录shell调用bash执行.bash_profile,如果存在的话,以完全相同的方式source做,所以效果是一样的。