7
8

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.

SSHが切れてもOK、nohupコマンドで標準出力のログを保存しておく

Last updated at Posted at 2015-05-21

サーバーでコマンドを叩いた時に、SSHのコネクションが切れてしまい標準出力ログがわからない!!みたいなことがあります。

コマンドの前にnohupを付ける

サーバーでnohupをつけてコマンドを実行します。

nohupの使用方法
nohup コマンド名

以下はrakeコマンドにnohupを付けた例です。

nohupでコマンドを実行
nohup bundle exec rake db:migrate

コマンドの出力はnohup.outというファイルに保存されています。
あとはSSHから抜けてもログを見ることができました。

おまけ:nohup.outの出力先を指定する

nohup.outファイルは通常は./nohup.outに作成されます。
これを任意のファイルに出力する場合は>>で指定します。

nohupでコマンドの出力を保存する
nohup bundle exec rake db:migrate >> ~/hoge

すると~/hogeファイルにが生成され標準出力が書き込まれます。

7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?