![로컬 컴퓨터에서 원격 스크립트 실행](https://linux55.com/image/157784/%EB%A1%9C%EC%BB%AC%20%EC%BB%B4%ED%93%A8%ED%84%B0%EC%97%90%EC%84%9C%20%EC%9B%90%EA%B2%A9%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%20%EC%8B%A4%ED%96%89.png)
로컬 및 원격 시스템은 모두 Centos 7 시스템이며 로컬 시스템에서 원격 스크립트를 실행하면 스크립트는 /home/user_name/scripts 디렉토리에 있습니다.
다음 메시지가 나타납니다.
$ ssh [email protected] "bash -s" -- < scripts/machine-info.sh
-bash: scripts/machine-info.sh: No such file or directory
이 명령을 실행하면 예상된 결과가 반환됩니다.
$ ssh [email protected] 'scripts/machine-info.sh'
date is: Thu Jul 25 01:43:35 CEST 2019
Hostname is: linuxtb3
IP address is: 192.168.1.xx
또한
$ ssh [email protected] 'bash -s -- < scripts/machine-info.sh'
date is: Thu Jul 25 01:45:13 CEST 2019
Hostname is: linuxtb3
IP address is: 192.168.1.xx
이 명령이 이 답변을 반환하는 이유는 무엇입니까?
$ ssh [email protected] "bash -s" -- < scripts/machine-info.sh
-bash: scripts/machine-info.sh: No such file or directory
답변1
당신의 명령에 따라
ssh [email protected] "bash -s" -- < scripts/machine-info.sh
리디렉션은 scripts/machine-info.sh
로컬에서 발생합니다. 이는 명령의 리디렉션 ssh
이며 데이터는 원격 프로세스의 표준 입력으로 종료됩니다 bash -s
(파일이 로컬에 존재하지만 존재하지 않는 경우 오류가 발생하는 이유입니다).
보여주신 다른 예에서는 스크립트가 원격 시스템에서 액세스되었습니다.
예를 들어,
ssh [email protected] 'bash -s -- < scripts/machine-info.sh'
명령 문자열을 작은따옴표로 묶었기 때문에 리디렉션은 원격 시스템에서 실행되는 명령의 일부입니다.