Issue
I need to execute a script using an ssh connection, the script then should execute a second script through a second ssh connection.
As of now, the scripts are created, copied, and executed correctly. However, in the last shh connection, a command in the script doesn't seem to get the options at all.
This is an example of what I have:
Script1, executed with ssh -T user@machine1 'script1.sh'
from a local machine:
#!/bin/sh
*Copy script2.sh in the correct destination on machine2 using scp*
ssh -T user@machine2 'location/script2.sh'
Script2, executed by the first script from machine1:
#!/bin/sh
cd path/of/script2
*some stuff not relevant*
bjobs -V #command with problems
When the script is executed manually on machine2 it works without any problem, when the same script is executed through the ssh connection I get Unknown option: V
.
I tried all I can think of or found on the internet:
bjobs \-V # Unknown option: V
bjobs '-V' # Unknown option: V
options=( -V )
bjobs "\${options[@]}" # Unknown option: V
command="bjobs -V"
eval \$command # Unknown option: V
I tried with other commands and I get:
ls -lla # Ignore the -lla option
options=( -lla )
ls "\${options[@]}" # Works correctly
free -g # Works correctly
options=( -g)
free "\${options[@]}" # Works correctly
All of these variants work correctly if I manually connect through machine1 and machine2 and execute the script with ./script2
.
Does anyone have an idea of what is going on? I'm out of ideas.
EDIT with suggestions from tripleee:
ssh -T user@machine2
type bjobs
bjobs is /usr/share/lsf/9.1/linux2.6-glibc2.3-x86_64/bin/bjobs
ssh -T user@machine2 type bjobs
bjobs is /usr/bin/bjobs
Solution
The immediate fix is to add /usr/share/lsf/9.1/linux2.6-glibc2.3-x86_64/bin
to your PATH
at the beginning of your script, or use the full path to the bjobs
version you want to run.
PATH=/usr/share/lsf/9.1/linux2.6-glibc2.3-x86_64/bin:$PATH
or
:
/usr/share/lsf/9.1/linux2.6-glibc2.3-x86_64/bin/bjobs -V
Answered By - tripleee