1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Linux】サーバ上に調査結果を保存して、ローカルにコピーする

Posted at

システムの不具合調査などでサーバに入ってlogを調査する際、そのlogを保存したり、ローカルにコピーしたりしたいことってよくありますよね。

でも、そういう時に限ってコマンドや書き方を忘れてしまい、急いでググることもまたよくありますよね。

調査時に使いそうなコマンドを自分のメモとして書き起こします。

シーン1:hogehoge.logファイルを開き、fugafugaが含まれる行を抽出し、結果をtmpディレクトリ直下に 'piyopiyo.txt'という名前で保存する

cat hogehoge.log | grep 'fugafuga' > /tmp/piyopiyo.txt

使うのは'cat'と'grep'と'>(リダイレクション)'と'|(パイプ)'

ちなみに、リダイレクションは'>'で上書き、'>>'で追記になり、ファイルが存在しない場合はどちらも新規作成されます。
参考:https://shellscript.sunone.me/input_output.html

シーン2:ssh鍵を指定してリモートサーバーからローカルのDesctopにpiyopiyo.logを保存する

scp -i 秘密鍵ファイル user@IP:/tmp/piyopiyo.txt ~/Desktop/

使うのは'scp'

秘密鍵を用いて接続する場合はiオプションを指定してあげます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?