General
cancel
Showing results for 
Search instead for 
Did you mean: 

how to call shell script from another node?

friend_1
Occasional Advisor

how to call shell script from another node?

Hi,

i configuared ssh for server(rac1,rac2). i have created one script in rac1 node. i am getting following error when calling script

in RAC1:
rac1-~> one.sh
echo "Welcome"

in RAC2:

rac2-~>cat two.sh
ssh rac1 one.sh
echo "Welcome to ALL"

rac2-~>sh two.sh
sh:command not found

Thanks,
5 REPLIES
Fredrik.eriksson
Valued Contributor

Re: how to call shell script from another node?

try doing it like this instead. Since you're not logging in via a proper shell when trying to execute a command with ssh you don't get the $PATH set either I believe.
You can test this by doing this:
ssh rac2 "echo $PATH"

My solution to your problem is something like this:
ssh rac2 "/bin/sh /path/to/one.sh"

Best regards
Fredrik Eriksson
Dennis Handly
Acclaimed Contributor

Re: how to call shell script from another node?

>i have created one script
>cat two.sh
ssh rac1 one.sh
echo "Welcome to ALL"
>sh two.sh

Ideally you should have your shell on the first line of your script and then make it executable:
#!absolute-shell-path

You then could execute your script with either:
two.sh
./two.sh # depending on your $PATH
Fredrik.eriksson
Valued Contributor

Re: how to call shell script from another node?

Oh sry, noticed that my test string isn't gonna work.

It'll just echo the $PATH on your local machine.
Might be able to do this with a eval or something else.

Don't give me any points for this post

Best regards
Fredrik Eriksson
Dennis Handly
Acclaimed Contributor

Re: how to call shell script from another node?

>Fredrik: It'll just echo the $PATH on your local machine.

Put it in single quotes: ssh rac2 'echo $PATH'
mohamed.bouraoui
Frequent Advisor

Re: how to call shell script from another node?

To execute this script yo ushould make :

ssh rac1 "/bin/sh two.sh"
or
ssh rac1 "exec tow.sh"

but before you make this verify if :
1- first line of script could have this line:
#/bin/sh
2- make your script executable by perfome this command
chmod 755 tow.sh
3- if the remote user is don't the same local user; yo ushould make -l derective like
ssh -l remote_user rac1 "/bin/sh two.sh"

I hope that help you.