I am trying to write a script that will:
- Copy files to a server (I already have a script
copy.sh
that does this task) - ssh to that server
- cd to the directory where the files I just copied are
- run
make
- copy the resulting binary from
make
to another location.
My script looks like this:
#!/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"
The issue is that a program I want to run as part of make
is not in my PATH
. My .bash_profile
has a export PATH=$PATH:/my/bin/
line, but it seems that bash_profile
is not being read when I ssh in.
Is there a way to change my ssh invocation or script in general to make it read my .bash_profile
?
Best Answer
The following should work:
The
source
shell builtin reads a file and executed the commands in the same shell (unlike simply calling the script, which invokes a separate shell).When invoked as login shell,
bash
executes the.bash_profile
, if it exists, in exactly the same way assource
does, therefore the effect will be the same.