Unixでローカルサーバー上のリモートサーバー上のファイルの内容を読み取るには? [閉鎖]

Unixでローカルサーバー上のリモートサーバー上のファイルの内容を読み取るには? [閉鎖]

results.txtファイルは私のローカルサーバーにありますが、results.txtの内容を1行ずつ読んでリモートサーバーでいくつかの操作を実行したいと思います。

どうすればいいですか?

答え1

  • 最初 - リモートサーバーにあるとし、リモートサーバーからローカルファイルをインポートするには、次の手順を実行します。 ssh UserName@LocalMachineIPWhciFileonit cat /path/to/result.txt
  • 第二 - 探してみてください:
    1. ファイルにフルパスが含まれている場合:if [ -f ... ]
    2. locateそうでない場合、またはコマンドを使用できますfind

ファイルに完全なファイル名アドレスがあるとします。 for i in $(ssh UserName@LocalMachineIPWhciFileonit cat /path/to/result.txt);do if [ -f $i ];then cp $i /NewPathYouWould fi;done

あなたの答えが正しいことを願っています。

答え2

ssh他のパイプを介して行うようにファイルの内容を提供できます。

# Create sample file
cat >>/tmp/file <<'EOF'
apple
banana
cherry
EOF

# Run 'nl' locally
nl </tmp/file
     1  apple
     2  banana
     3  cherry

# Run 'tac' on the remote server 'rserver'
nl </tmp/file | ssh rserver tac
     3  cherry
     2  banana
     1  apple

# Postprocess result locally
nl </tmp/file | ssh rserver tac | grep ana
     2  banana

# Tidy up
rm -f /tmp/file

関連情報