2017-09-29 10 views
0

나는한 줄 명령은 여러 ssh 명령을 실행

host1 
host2 
host3 

내가 뭘 원하는 내가 한 줄을 사용하는 방법을

ssh host1 'my command' 
ssh host2 'my command' 
ssh host3 'my command' 

호스트 정보가 포함 된 파일, 하나의 호스트 하나 개의 라인했다 명령 (복잡한 쉘 스크립트가 아님)을 구현하려면

답변

1

당신이 원하는 것은 너무 복잡합니까?

for h in $(<file); do ssh $h 'my command'; done 

은 또 다른 가능성 :

cat file | xargs -I% -- ssh % 'my command' 

이하는 :

<file xargs -I% ssh % 'my command' 
:

<file xargs -I% -- ssh % 'my command' 

또는 경우 짧은 있는지 당신은 당신의 ssh 명령의 모든 - 옵션이 없습니다

0
while read -r line; do ssh "$line" 'my command'; done < host 

이 명령은 파일을 한 줄씩 읽은 다음 변수 $line에 입력하십시오. 그리고 호스트 저장과 함께 ssh 명령을 실행하십시오 $line

관련 문제