stdin は端末ではないため、擬似端末は割り当てられません。質問する

stdin は端末ではないため、擬似端末は割り当てられません。質問する

リモート サーバーにいくつかのディレクトリを作成し、scp を使用してローカル マシンからリモートにファイルをコピーするシェル スクリプトを作成しようとしています。これまでに作成したものは次のとおりです。

ssh -t user@server<<EOT
DEP_ROOT='/home/matthewr/releases'
datestamp=$(date +%Y%m%d%H%M%S)
REL_DIR=$DEP_ROOT"/"$datestamp
if [ ! -d "$DEP_ROOT" ]; then
    echo "creating the root directory"
    mkdir $DEP_ROOT
fi
mkdir $REL_DIR
exit
EOT

scp ./dir1 user@server:$REL_DIR
scp ./dir2 user@server:$REL_DIR

実行するたびに次のメッセージが表示されます:

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

そしてスクリプトは永遠にハングしたままになります。

私の公開鍵はサーバー上で信頼されており、スクリプトの外部ですべてのコマンドを問題なく実行できます。何かアイデアはありますか?

ベストアンサー1

stdin が端末でない場合でも、擬似 tty の割り当てを強制しようとしますssh -t -t(または略して強制します)。ssh -tt

参照:bash スクリプトによって実行された SSH セッションを終了する

ssh のマニュアルページより:

-T      Disable pseudo-tty allocation.

-t      Force pseudo-tty allocation.  This can be used to execute arbitrary 
        screen-based programs on a remote machine, which can be very useful,
        e.g. when implementing menu services.  Multiple -t options force tty
        allocation, even if ssh has no local tty.

おすすめ記事