Hayra Hayra - 11 months ago 55
Bash Question

Source environment variables and execute bash before running local script on remote machine

I'm trying to execute the remote local script with ssh connection. I've read a document about the syntax of it. But my issue is that, before running the script, I need to execute bash and source environment variables.

This looks appropriate for me but it has not a source command :

ssh [user]@[server] 'bash -s' < [local_script]

I've tried such a thing with EOF but it didn't work for me too :

/usr/bin/ssh "$user@$$host" <<EOF
bash -s
source /dir/to/profile/.profile
source /dir/to/env/set/env.sh
/path/to/script/script.sh stop

Do you have an idea for this type of implementation of remote commands ? I have to source profile before the environment settings otherwise it gives an exception. But the main problem is about source.

Maybe it was an easy question but I don't have any ideas. Thank you in advance for your all answers.

Answer Source

i fixed problem as writing another template script which source the environment variables and run the script. And it hopefully works.

source $PROFILE
cd /dir/to/script
/bin/bash script $1

If you use source command with bash shell, #!/bin/bash doesn't work for source command.

Thank you for all your comments.