I'm using some old Fortran code that uses some peculiar memory handling. To make the long story short, it runs on my local machine but fails on the remote one. This is why I would like to ssh
to my local computer run the code and copy the results back to the cluster I'm running my calculations on.
I already found exactly the same question on this forum:
EDIT #1
After the comment by @Anthon, I corrected my script, unfortunately new error occurred. NOTE: I am using ssh keys so no passwords are needed.
My new script:
#! /bin/bash
# start form the machine_where_the_resutlst_are_needed
ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/run.sh inp 8
# do the work by running a script. 8 jobs are run by sending them
# to the background,
scp -p usr@machene_wehere_i_run_the_code:/home/run_dir_script/results \
user@machine_where_the_resutlst_are_needed:~/
echo "I am back"
My problem is that run.sh
is a master script calling other shell scripts, and they don't run properly. I get the following message:
/home/run_dir_script/run.sh: line 59: /home/run_dir_script/merge_tabs.sh: No such file or directory
Minimal Example:
Here is a condensed example of what I am doing
Example run.sh
#! /usr/bin/bash
pwd
echo "Run the code"
./HELLO_WORLD
The above script is run by
ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/run.sh
For completeness the fortran code ./HELLO_WORLD
program main
write(*,*) 'Hello World'
stop
end
Compile with gfortran -o HELLO_WORLD hello_world.F90
And here is the output
/home/run_dir_script/
Run the code
/home/run_dir_script/test.sh: line 5: ./home/HELLO_WORLD: No such file or directory
Remark:
The following will run `HELLO_WORLD` on the remote machine
ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/HELLO_WORLD
So calling the code directly works fine. Calling it via the script fails.
Possible Solution:
The reason why this fails is due to the fact that after ssh I land in my remote machine's $HOME
.
Therefore before executing the script, I have to cd
in the proper directory. The correct method, besides giving absolute path is:
Another useful remark, is that I all the variables from .bashrc are undefined. Therefore one has to be careful.
usr@machene_wehere_i_run_the_code "cd /home/run_dir_script ; run.sh"
So this somehow works
/home/run_dir_script/run.sh
(on the remote machine) say? What is the output ofls -l /home/run_dir_script/merge_tabs.sh
(on the remote machine)? – Marki Nov 16 '14 at 14:24merge_tabs.sh
is run. Basically I can call a script on the remote machine, but this script can't call other scripts. All scripts and binaries have permissions777
, therefore, permissions should not be causing this problem – Alexander Cska Nov 16 '14 at 14:41ls -l /home/run_dir_script/merge_tabs.sh
says. ;-) – Marki Nov 16 '14 at 14:43-rwxrwxrwx 1 user users 374 Nov 14 15:41 /home/run_dir_script/merge_tabs.sh*
. Actually this problem is not only for scripts but for all codes run withinrun.sh
. I rote a small fortran code that prints "Hello World" andrun.sh
issued the same error. – Alexander Cska Nov 16 '14 at 14:49./HELLO_WORLD
run when you simply login to the remote and execute it? – slm Nov 16 '14 at 15:13ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/HELLO_WORLD
. – Alexander Cska Nov 16 '14 at 15:15#!/bin/bash
. – slm Nov 16 '14 at 15:19#!/bin/bash -l
didn't work either. – Alexander Cska Nov 16 '14 at 15:21./HELLO_WORLD
with justls
? – slm Nov 16 '14 at 15:23/home/run_dir_script/HELLO_WORLD
should replace line 5 inrun.sh
. It is quite strange that the path should be hardcoded. For instance$(pwd)/HELLO_WORLD
won't work. Can you try running my minimal example on some remote machine of yours. I am curious what your test would yield . – Alexander Cska Nov 16 '14 at 15:36echo "Hello World"
, or I could have used C or Java or whatever. In this case somehow the shell can't find the path, but I have no idea why. – Alexander Cska Nov 16 '14 at 16:01