1

I work with machine A and I want to run a script that exists in machine B.

I did the ordinary command:

ssh user@machine_B_adress '. script.sh'

the problem is that I used in the script some commands that cannot be interpret with machine A. So I get command not found: (for example)

ksh: sqlplus:  not found

I tried to open a shh by: ssh user@machine_B_adress

and then run the script, it works!!!

5
  • 1
    Have you tried ssh user@machine_B_address '/bin/bash -l .script.sh'? Commented Apr 18, 2017 at 14:57
  • bash is not installed in the remote machine and I can't install it; Simply, coz I m not allowed to do it Commented Apr 18, 2017 at 15:22
  • I get: ksh: /bin/bash: not found Commented Apr 18, 2017 at 15:34
  • could you run the following commands and paste the output: when logged in: which sqlplus ps -ef | grep $$ | grep -v grep and echo "$PATH" and also all 3 as ssh user@machine_B_adress 'which sqlplus' ? Commented Apr 18, 2017 at 15:43
  • I get: no sqlplus in /usr/bin /etc ... after executing ssh user@machine_B_adress 'which sqlplus' Commented Apr 18, 2017 at 15:55

1 Answer 1

1

Assuming that the shell for user@machine_B is bash, the first example 'ssh user@machine_B_adress '. script.sh', bash sets up the shell env differently for interactive/non-interactive sessions.

See man bash about interactive shells

Looks like you can emulate the interactive environment by adding a bash -l -c

$ ssh user@machine_B_address "bash -l -c '. script.sh'

My quick test, I added debug echo to .bash_profile of the remote user

$ ssh foouser@jdsrpi1 "bash --login -c '. foo.sh'"

This is file .bash_profile

foouser 

SHELL = /bin/bash

PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

Similar scenario for ksh

$ ssh [email protected] "date"
Tue Apr 18 11:52:43 EDT 2017

$ ssh kshuser@jdsdrop1 "ksh -l -c date"

This is SHELL(/usr/bin/ksh) file .profile

Tue Apr 18 11:53:24 EDT 2017
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for responding; But if it's ksh?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.