LoginSignup
4
7

More than 5 years have passed since last update.

tmuxでログを自動取得

Posted at

参考 https://memo.laughk.org/2014/12/09/tmux-ssh-logging.html

本当はターミナルアプリのログ取得機能を使いたいのだけど、
tmux/screenで画面分割なんかしてるとログが使い物にならないので下記で対応。

# .bashrc, .zshrc等に下記を追加
if [[ $TERM = screen ]] || [[ $TERM = screen-256color ]] ; then
  LOGDIR=$HOME/Documents/term_logs
  LOGFILE=$(hostname)_$(date +%Y-%m-%d_%H%M%S_%N.log)
  [ ! -d $LOGDIR ] && mkdir -p $LOGDIR
  tmux  set-option default-terminal "screen" \; \
    pipe-pane        "cat >> $LOGDIR/$LOGFILE" \; \
    display-message  "Started logging to $LOGDIR/$LOGFILE"
fi
4
7
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
4
7