인라인 SSH 명령


15

간단한 인라인 스타일 SSH 명령을 수행 할 수 있습니까? 예를 들면 다음과 같습니다.

ssh foo@bar.com { cd foo/bar && rm *.foobar }

답변:


27

cd foo/bar && rm *.foobar원격 컴퓨터에서 실행하려면 간단히

ssh foo@bar.com  'cd foo/bar && rm *.foobar'

그리고 참조 man ssh...

ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D
[bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L   [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R
[bind_address:]port:host:hostport] [-S ctl_path] [-w tunnel:tunnel
[user@]hostname [command]

원하는 부분 :

ssh [user@]hostname [command]

2
이 방법을 사용하여 STDIN 및 STDOUT을 파이프 할 수 있다는 점에 주목할 필요가 있습니다. 요즘에는 s over ssh를 사용하여 원격 시스템의 HD 이미지를 만들었습니다.
crazy2be

9

스타일 1 : ssh user@host 'embedded command'

스타일 2 : ssh user@host " $(cat cmd.txt) "
cmd.txt는 로컬 컴퓨터에있는 원격 명령을 포함하는 파일입니다.


7

그렇습니다 :

ssh foo@bar.com 'cd foo/bar && rm *.foobar '
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.