
나는 100개의 서버를 가지고 있고 스크립트를 사용하여 중앙 서버에서 ssh로 서버에 로그인해야 합니다. 아래에서 이를 시도하여 중앙 서버에 저장될 파일로 리디렉션된 버전을 얻어야 합니다.
#!/bin/bash
CMD='java -version'
while read line
do
ssh -n user@"$line" $CMD >> /pathforoutputfile/outputjava.txt
done < /pathforhosts/hosts.txt
하지만 파일에서 출력이 생성되지 않습니다./pathforoutputfile/outputjava.txt
답변1
해당 명령은 실제로 stderr에 기록됩니다.
ron@haggis:~$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
ron@haggis:~$
ron@haggis:~$ java -version 2> foo.txt
ron@haggis:~$ cat foo.txt
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
따라서 in 2>>
대신에 using을 사용하여 리디렉션해야 합니다.>>
ssh -n sgarole@"$line" $CMD >> /pathforoutputfile/outputjava.txt
내가 알아차린 또 다른 점은 /pathforoutputfile/outputjava.txt
.