とあるエンジニアの技術記録

主にWindowsやLinuxの設定方法、トラブル解決方法について投稿してます~♪

SquidのログファイルのUNIX時間の変換方法

2012年02月08日 15時32分39秒 | Linux
Redhat5.7のSquidのログ(/var/log/access.log, /var/log/store.log)のタイムスタンプはUNIX時間で表示されており、1970年1月1日からの経過時間が表示されており、実際に何日何時に記録されたログか分からない。

ただし以下のコマンドを実行してUNIX時間を現在の時間に変換することができるので、その方法を纏めておきます。

(1)perlサービスが使用できるかの有無
「perl -v」コマンドを実行してperlが使用できるか確認します。
使用できる場合は以下のように表示されます。
 [root@server]# perl -v
 This is perl, v5.8.8 built for x86_64-linux-thread-multi

 Copyright 1987-2006, Larry Wall

 Perl may be copied only under the terms of either the Artistic  
 License or the GNU General Public License, which may be found in
the Perl 5 source kit.

 Complete documentation for Perl, including FAQ lists, should be
 found on this system using "man perl" or "perldoc perl".
If you have access to the Internet, point your browser at
http://www.perl.org/, the Perl Home Page.

(2)UNIX時間から現在の時刻への変更
以下のコマンドを実行し、/var/log/squid/access.logファイルをリダイレクトして現在の時刻に変換されたログファイル(access_time.log)を作成します。
 [root@server]# perl -pe 's/\d+\.\d+/localtime $&/e' /var/log/squid/access.log > access_time.log

以上

▼参考URL
http://d.hatena.ne.jp/tofoo/20041102/p2


コメントを投稿