スクリプトの疑似端末メッセージ

スクリプトの疑似端末メッセージ

これは私のスクリプトです。

#!/bin/bash
exec < filelist.txt
    while read updatedfile oldfile; do
    #   echo updatedfile = "$updatedfile" #use for troubleshooting
    #   echo oldfile = "$oldfile" #use for troubleshooting
               if [[ ! $updatedfile =~ [^[:space:]] ]] ; then  #empty  line exception
                continue # empty line exception
               fi
               if [[ ! $oldfile =~ [^[:space:]] ]] ; then  #empty line exception
                continue # empty line exception
               fi 
            echo Comparing $updatedfile with $oldfile
            if diff "$updatedfile" "$oldfile" >/dev/null ; then
                echo The files compared are the same. No changes were made.
            else
                echo The files compared are different.
                cp -f -v $oldfile /infanass/dev/admin/backup/`uname -n`_${oldfile##*/}_$(date +%F-%T)
                cp -f -v $updatedfile $oldfile 
            fi          
    done
#go through rest of servers from list
while read server <&3; do   #read server names into the while loop    
serverName=$(uname -n)
 if [[ ! $server =~ [^[:space:]] ]] ; then  #empty line exception
    continue
 fi   
 echo server on list = "$server"
 echo server signed on = "$serverName"
 if [ $serverName == $server ] ; then #makes sure a server doesnt try to ssh to itself
    continue
 fi
    echo "Connecting to - $server"
    ssh "$server"  #SSH login
    exec < filelist.txt
    while read updatedfile oldfile; do
    #   echo updatedfile = $updatedfile #use for troubleshooting
    #   echo oldfile = $oldfile   #use for troubleshooting
               if [[ ! $updatedfile =~ [^[:space:]] ]] ; then  #empty line exception
                continue # empty line exception
               fi
               if [[ ! $oldfile =~ [^[:space:]] ]] ; then  #empty line exception
                continue # empty line exception
               fi 
            echo Comparing $updatedfile with $oldfile
            if diff "$updatedfile" "$oldfile" >/dev/null ; then
                echo The files compared are the same. No changes were made.
            else
                echo The files compared are different.
                cp -f -v $oldfile /infanass/dev/admin/backup/`uname -n`_${oldfile##*/}_$(date +%F-%T)
                cp -f -v $updatedfile $oldfile 
            fi          
    done
done 3</infanass/dev/admin/servers.txt

SSHを介してサーバーのリストに接続しようとするとエラーが発生します。

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

その後、私のスクリプトはsshを正しく失敗し、新しいログインサーバーのファイルを比較します。なぜこれを知っている人がいますか?

ベストアンサー1

ssh "$server"get以降のすべてのコマンドがssh内で実行されると思いますか?そのようなことは起こりませんでした。他のパラメータなしでホスト名でsshを使用して対話型セッションを開始します。終了後、スクリプトは次のコマンド(exec < filelist.txt)を実行し続けます。これはssh内のリモートコマンドではありません。コマンドが到着すると、sshは完了して消えました。これは埋め込みスクリプトの一般的な順次実行です。

stdinがリダイレクトされた対話型SSHセッションはかなり珍しいです。それがあなたが警告を受けた理由です。 (警告を抑制するには、-tまたはを使用できます-T

SSH接続を介して大規模なスクリプトを渡してリモートで実行するには、次のものを使用できます。ここのドキュメント、このように:

ssh "$server" sh <<EOF
your big script here...
EOF

ローカルスクリプトで拡張する必要がある変数と、リモートスクリプトの実行中に拡張する必要がある変数を慎重に検討してください。$Heredocの保護されていないコンテンツはデフォルトで拡張されています。リモートシェルが見えないようにするには、を$使用します\$。これらすべてを保護するに<<EOFはに変更できます<<'EOF'

おすすめ記事