MSN log merger
2007-01-18 19:04
好吧, 順利把一些 data 在一堆機器上 sync 後
又另外想搞個東西 ....
這就像 cclien 的 象牙筷子事件 一樣, 愈滾愈多洞 XD
兩台 windows 都有裝 MSN ,
因為一台家用一台公司用, 所以之前在兩台上面都會各有一份 log
現在既然要把資料都 sync 在一起了,
自然會想把兩台上的 log 先 merge , 以後留一份就好 ...
於是分析了一下 msn log 的格式,
然後寫了個簡單的 merger ...
Usage: ./merge.pl file1 file2 file3 .... > newfile
寫一寫總得驗證一下到底做得對不對呀 ~
如果每次 merge 完還得拉進 windows 檢查的話 很麻煩
於是又寫了隻程式用來顯示 parse 出來的紀錄 ...
(註:閱讀時 character set 請使用 UTF-8)
Usage: ./show.pl [-{123}] filename
-1 : normal format
-2 : simple format (default)
-3 : html format
Tips:
cat filename | ./show.pl
merge.pl file1 file2 | ./show.pl
./show.pl filename | less -R
./show.pl filename > newfile
寫完後, 把兩份 log 分別放置於 home 及 sti 這兩個目錄中
(因為檔名一樣 不能放同個地方 不然會蓋到)
然後寫個 script 下去跑 ...
#!/bin/sh
DIR1=”home”
DIR2=”sti”
NEWDIR=”new”
if [ ! -d $NEWDIR ] ; then
echo “mkdir $NEWDIR/”
mkdir $NEWDIR
fi
for file in `ls $DIR1 $DIR2 | grep “\.xml” | sort | uniq`
do
echo “perl merge.pl $DIR1/$file $DIR2/$flie > $NEWDIR/$file”
perl merge.pl $DIR1/$file $DIR2/$file > $NEWDIR/$file
done
再把 new/ 這個目錄裡的檔案搬回 windows 裡放 msn log 的目錄
就收工了 :>
要注意的是,
每個 log 最多只能存 8192 條訊息,
超過的話 要在 msn 裡開啟該 log 時, 會有警告訊息
提示你可以把舊一點的 log 存到另一個檔案中....
以下提供程式的原始碼, 有興趣的人請自己修改使用
但 “使用前請自行備份” , 如有損毀到您的資料 , 本人將不負任何責任 :>
程式的原始檔 : (因為有些是 UTF-8 字元, 最好用 wget 直接抓)
merge.pl
show.pl
如果想在 windows 上用的話,
我也順便提供了編成的 .EXE 檔方便使用 :)
merge.exe
show.exe
但 Windows 上的 命令提示字元 無法正確顯示 UTF-8 的字元,
因此在使用 show 的時候, 可以轉完後導到另一個檔案, 然後由 UltraEdit 之類的軟體開啟
或是使用 -3 轉成 html , 再由 Browser 開也可以.
Novell iFolder 3 + rsync哇哈 ~ 我出運了 !
.Perl 類別的文章 :
Re: CGI encrypt?wget.pl
1 則留言 新增留言
1. Waldir | March 21st, 2007 at 08:39
I tried your software but it didnt work because i dont have python installed. I have programmed an application that does that, cause i needed such a thing; if you wish i can send you the exe or the source code, i'd like to release that online.
新增留言
訂閱這則留言的 RSS Feed