How to execute setDomainEnv.sh in wblogic via ssh on remote server in shell script?

How to execute setDomainEnv.sh in wblogic via ssh on remote server in shell script

we execute setDomainEnv.sh manually as . ./setDomainEnv.sh from its location ie /opt/SP/users/domian/bin "

My approach is not working.

Please advise.

#!/bin/bash
set -x
base="/opt/SP/users/d1/bin"
COM="(. ./setDomainEnv.sh)"

for i in server1 server2 ....servern

ssh -t user1@i "cd $base";"$COM""
         done

WHAT is "not working"?

Try removing the double quotes around the semicolon in the ssh command.

is not working. means
This script . ./setDomainEnv.sh is not getting executed.

--- wrong guess deleted ---

This:

cannot work. I suppose setDomainEnv.sh contains some settings you want to incorporate in this (and probably other) script(s). To do so you need to execute it in this environment but the "(...)" (which means do what is inside the parentheses in a subshell is exactly the opposite of that - it will execute it in another environment (even if you remove the quotes, which perhaps make sure that the string is not executed at all).

Replace the line with

. ./setDomainEnv.sh"

and if you need the return code of the script (this might be why you tried to do it with the subshell) do it like this:

. ./setDomainEnv.sh"
COM=$?

Another point is: it is strongly discouraged to use relative pathes in a script, because what is ./.... depends on where you are at the moment of script execution. This will work from one directory but not from another. Always do it like this (absolute path) :

. /path/to/setDomainEnv.sh"
COM=$?

because the absolute path will work regardless of what your PWD is right now.

I hope this helps.

bakunin

Thanks bakunin for your help.