2017-03-20 4 views
1

heredocumentを使用してケルベロスのプリンシパルのリストを取得しようとしています。ここの文書の出力をテキストファイルにリダイレクトする方法は?

heredocumentの出力をテキストファイルにリダイレクトする方法を教えてください。 以下はテキストファイルへのリダイレクトなしのスクリプトの動作です。

#!/bin/bash 

ssh [email protected] <<-EOF 
kadmin.local 
list_principals *host1* 
EOF 

output: 
HTTP/[email protected] 
hadoop/[email protected] 
host/[email protected] 

しかし、出力ファイルをテキストファイルにリダイレクトしようとすると、エラーが発生します。働いdin't

もの:

#!/bin/bash 
ssh [email protected] <<-EOF > test.txt 
kadmin.local 
list_principals *host1* 
EOF 

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

#!/bin/bash 
ssh [email protected] cat <<-EOF > test.txt 
kadmin.local 
list_principals *host1* 
EOF 

output: 
kadmin.local 
list_principals *host1* 
+0

、 '' -Tためssh' 'で-T'を使用する可能性があり擬似端末割り当てを無効にする。 – Inian

答えて

2
#!/bin/bash 
ssh [email protected] > test.txt <<-EOF 
kadmin.local 
list_principals *host1* 
EOF 

テスト:

$ sh > out.dat <<- EOF 
date 
EOF 

$ cat out.dat 
Mon Mar 20 09:49:18 EDT 2017 
関連する問題