
저는 독특한 메모리 처리를 사용하는 오래된 Fortran 코드를 사용하고 있습니다. 간단히 말해서, 내 로컬 컴퓨터에서는 실행되지만 원격 컴퓨터에서는 실패합니다. 이것이 ssh
바로 로컬 컴퓨터에서 코드를 실행하고 계산을 실행 중인 클러스터에 결과를 다시 복사하고 싶은 이유입니다 .
나는 이미 이 포럼에서 똑같은 질문을 발견했습니다.
편집 #1
@Anthon의 댓글 이후 스크립트를 수정했는데 안타깝게도 새로운 오류가 발생했습니다.메모:SSH 키를 사용하고 있으므로 비밀번호가 필요하지 않습니다.
내 새 스크립트:#! /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"
내 문제는 run.sh
다른 쉘 스크립트를 호출하는 마스터 스크립트인데 제대로 실행되지 않는다는 것입니다. 다음 메시지가 나타납니다.
/home/run_dir_script/run.sh: 59행: /home/run_dir_script/merge_tabs.sh: 해당 파일이나 디렉터리가 없습니다.
최소한의 예:
다음은 내가 하고 있는 일에 대한 요약된 예입니다.
예run.sh
#! /usr/bin/bash
pwd
echo "Run the code"
./HELLO_WORLD
위 스크립트는 다음에 의해 실행됩니다.
ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/run.sh
완전성을 위해 포트란 코드 ./HELLO_WORLD
program main
write(*,*) 'Hello World'
stop
end
gfortran -o HELLO_WORLD hello_world.F90으로 컴파일
그리고 여기에 출력이 있습니다.
/home/run_dir_script/
Run the code
/home/run_dir_script/test.sh: line 5: ./home/HELLO_WORLD: No such file or directory
주목:
The following will run `HELLO_WORLD` on the remote machine
ssh usr@machene_wehere_i_run_the_code /home/run_dir_script/HELLO_WORLD
따라서 코드를 직접 호출하면 문제가 없습니다. 스크립트를 통해 호출하면 실패합니다.
가능한 해결책:
이것이 실패하는 이유는 ssh 후에 원격 시스템의 $HOME
.
cd
따라서 스크립트를 실행하기 전에 적절한 디렉터리에 있어야 합니다 . 절대 경로를 제공하는 것 외에 올바른 방법은 다음과 같습니다.
또 다른 유용한 점은 .bashrc의 모든 변수가 정의되지 않았다는 것입니다. 그러므로 조심해야 합니다.
usr@machene_wehere_i_run_the_code "cd /home/run_dir_script ; run.sh"
그래서 이것은 어떻게든 작동합니다
답변1
ssh
나는 인수를 큰따옴표로 묶으려고 합니다 .
ssh usr@machene_wehere_i_run_the_code "/home/run_dir_script/run.sh inp 8"
또한 해당 오류 메시지에 따르면 스크립트가 이 스크립트를 찾을 수 없는 것 같습니다.
/home/run_dir_script/run.sh: 59행: /home/run_dir_script/merge_tabs.sh: 해당 파일이나 디렉터리가 없습니다.
또한 성공적인 상태를 반환하지 않으면 해당 일이 scp
발생하지 않도록 차단합니다 .ssh
ssh usr@machene_wehere_i_run_the_code "/home/run_dir_script/run.sh inp 8"
status=$?
if $status; then
scp -p usr@machene_wehere_i_run_the_code:/home/run_dir_script/results \
user@machine_where_the_resutlst_are_needed:~/
fi
그러나 중요한 문제는 원격 시스템에서 하위 스크립트를 찾는 스크립트에 문제가 있다는 것입니다. 로그인하여 스크립트를 실행할 때 설정되는 변수와 로그인하여 ssh
스크립트를 실행할 때 설정되는 변수가 있을 수 있습니다.
이를 위해 두 가지 방법을 모두 사용한 결과를 비교하겠습니다 env
.
답변2
ssh -X usr@machene_wehere_i_run_the_code
코드의 다음 줄에는 아무것도 없습니다 . 따라서 해당 명령은 로그인 machene_wehere_i_run_the_code
하고 아무 작업도 수행하지 않습니다.
인용한 질문의 허용된 답변에 있는 SSH 호출 예시에는 추가 매개변수가 있습니다.
ssh user@host path_to_script
그리고 path_to_script
당신의 것에는 이 것이 없습니다.