0
1

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.

terminalの作業ログを日付ディレクトリ別に残す

Last updated at Posted at 2016-12-27

小ネタですが・・・。

macでterminalを使っているとログを残したい!けど、
TeraTermと違ってどこにログ設定があるのや?となります。
(iTermを使えば終わる話ですね!)

https://bacchi.me/mac/terminallog-autosave/
http://qiita.com/imura81gt/items/1ffaaff3cc1e9613925f
上記の記事を参考にすればログファイルは作成できます。
が、いかんせんファイル数が肥大化しがちです。
とりあえず日付ごとにディレクトリを切れば少しは安心。

作業

$DIRはお好きなディレクトリに置き換えてご使用ください。

/etc/profile
TIMESTAMP=`date "+%Y%m%d-%H%M%S"`
DATE=`date "+%Y%m%d"`
DIR="$HOME/terminal-logs/$DATE"
if [ ! -d $DIR ]; then
    mkdir -p $DIR
fi
LOGFILE="$DIR/terminal-$TIMESTAMP.log"
script $LOGFILE
exit

保存して、新規にTerminalを立ち上げると、
~/terminal-logs/20161227/terminal-20161227-111321.log
上記のような形で作業ログが保存されていきます。

小ネタ

cat等で自身のログファイルを参照するとき、
タイミングが良いとcatの出力タイミングとログの書き込みタイミングがうまいことマッチしてループする模様です。
即Ctrl+Cで終了しましたが、一瞬で30MBくらいのログファイルが出来上がっていました。

そのうち

  • bash-3.2 が気に食わない問題をどうにかする
  • 前月以前のディレクトリを月ディレクトリにまとめたい
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?