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.

Macのterminalでのログを保存する

Last updated at Posted at 2014-02-20

執筆経緯

terminalの実行コマンドログを保存する必要性が出て来たので調べた。
Applicationのログ保存機能でも良かったが、せっかくなので/etc/profileをいじってみる
shell起動時にscriptが起動し、起動時刻でログファイルを生成するよう設定する

/etc/profileへのログ生成機能の追記

ログファイルの置き場所の作成

$ mkdir -p ~/log/termlog

suになる

$ su
Password:

#

所有者とアクセス権の確認

# ls -l /etc/profile
-r--r--r--  1 root  wheel  292  2 21 03:43 /etc/profile

編集を加えるためにアクセス権を変更する

# chmod 755 /etc/profile

タイムスタンプの定義とログファイルの作成、scriptコマンドの追記

/etc/profile
+ timestamp=`date "%Y%m%d-%H%M%S"`
+ logfile="$HOME/log/termlog/terminal_$timestamp.log"
+ script $logfile

アクセス権の戻しとshellの再起動

# chmod 444 /etc/profile
# exit
$
$ exit

ログファイルの圧縮

後日記載

一ヶ月前のファイルを一日ごとに分けてtgzするだけ。
find -mtime ~
tar -z

問題点

ログファイルをcatとかで見ると変な挙動を示す。なんだこれ汗

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?