![Unixでローカルサーバー上のリモートサーバー上のファイルの内容を読み取るには? [閉鎖]](https://linux33.com/image/137444/Unix%E3%81%A7%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E4%B8%8A%E3%81%AE%E3%83%AA%E3%83%A2%E3%83%BC%E3%83%88%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E4%B8%8A%E3%81%AE%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E5%86%85%E5%AE%B9%E3%82%92%E8%AA%AD%E3%81%BF%E5%8F%96%E3%82%8B%E3%81%AB%E3%81%AF%EF%BC%9F%20%5B%E9%96%89%E9%8E%96%5D.png)
results.txtファイルは私のローカルサーバーにありますが、results.txtの内容を1行ずつ読んでリモートサーバーでいくつかの操作を実行したいと思います。
どうすればいいですか?
答え1
- 最初 - リモートサーバーにあるとし、リモートサーバーからローカルファイルをインポートするには、次の手順を実行します。
ssh UserName@LocalMachineIPWhciFileonit cat /path/to/result.txt
- 第二 - 探してみてください:
- ファイルにフルパスが含まれている場合:
if [ -f ... ]
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