SSHスクリプトと実行コマンドが機能しない

SSHスクリプトと実行コマンドが機能しない

以下はスクリプトです。

複数のサーバーにログインしてカーネルのバージョンを確認したい。

#!/bin/bash
#input server names line by line in server.txt
cat server.txt | while read line
do
sshpass -p password ssh root@$line << EOF
hostname
uname -r
EOF
done

出力は次のようになると予想されます..

server1_hostname
kernel_version
server2_hostname
kernel_version

など..

私はserver.txtの約80台のサーバーでこのスクリプトを実行しました。

私が得た結果は次のとおりです...

Pseudo-terminal will not be allocated because stdin is not a terminal. 
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.

========================================================================
================================ WARNING ===============================
========================================================================
This system is solely for the use of authorized personnel. Individuals
using this system are subject to having some or all of their activities
monitored and recorded. Anyone using this system expressly consents to
such monitoring and is advised that any unauthorized or improper use of
this system may result in disciplinary action up to and including
termination of employment. Violators may also be subject to civil and/or
criminal penalties.
========================================================================

Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
xxxxdev01
2.6.32-431.23.3.el6.x86_64
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.

ここではホスト1つの出力のみを取得し、xxxxdev01SSHバナーやその他の警告も付属しています。

他のすべてのホストからの出力が必要で、SSHバナーは必要ありません。ここで何の問題がありますか?

ベストアンサー1

hostnameそして、コマンドが期待どおりの出力を取得できない理由を説明することはできませんが、関係のないunameテキストについては役に立ちます。

ssh実行するコマンドがコマンドラインに提供されていないときにデフォルトでTTY割り当てを試みるため、「疑似ターミナル」行が印刷されます。 sshコマンドに「-T」を追加すると、このメッセージを防ぐことができます。

sshpass -p password ssh -T root@$line

「警告:ttyにアクセスできません」行はリモートシステムのシェルから来ます。場合によっては、メッセージを印刷しますcsh。 TTYが必要な機能にアクセスしようとすると、リモートシステム上のファイルtcshまたは同様のファイル内のエントリによってトリガーされることがあります。.cshrc

おすすめ記事