Thursday, January 13, 2011

pipe, split, rotate

Recently I have to strace to monitor a long-running daemon. strace will generate a lot of output but it doesn't have a built-in way to split the output into files. At first, I have a few idea to solve the problem:

1. "split" command can split the output to files but it has a pre-set limit. For example, default it names the output file with suffix "aa", "ab"...., "zz" and then it will stop. You can increase suffix length but it will eventually stop.

2. Normal "logrotate" method would not work because strace will not accept SIGHUP (like httpd does) to close and open the log file.

3. Use a cronjob to "stop, rotate file and restart strace" - it will lost the trace between the stop and restart of strace.

I then try to write my own program to read the input and write to file and rotate. But after I finished, I search on web and find an existing program which can solve my problem: "rotatelogs". It comes with httpd package.

For example:

# strace -f -t -p | rotatelogs output_log 86400


It will write the output to output_log and rotate it every 86400s (24hrs). You can also specify the size of each output file.

Monday, June 14, 2010

Fedora 12 + SELinux + Firefox 3.6 + Sun Java plugin

Because of a legacy application, I need to install Sun Java plugin in my Fedora 12 system. There is a few tricks worth notice:

1. After Firefox 3.6, it doesn't support the original Java plugin format OJI and only support the standard NPAPI and NPRuntime interfaces that come with Sun Java 6 update 10 or later.

Ref. www.java.com/en/download/faq/firefox_newplugin.xml

You have to remove all libjavaplugin_oji.so link from firefox plugin directories (e.g. /usr/lib/mozilla/plugins, /usr/lib/firefox/plugins, ~/.mozilla/plugins, etc) and create this new link:

# ln -s /usr/java/jdk1.6.0_18/jre/lib/i386/libnpjp2.so libnpjp2.so


And restart firefox to take effect.

2.If you SELinux is disabled, it is all you need. But if SELinux is enabled, you will get this message when you start firefox in shell:

#./firefox
LoadPlugin: failed to initialize shared library /usr/java/jre1.6.0_20/lib/i386/libnpjp2.so [/usr/java/jre1.6.0_20/lib/i386/libnpjp2.so: cannot enable executable stack as shared object requires: Permission denied]

A quick and dirty way is to clear the "executable stack" flag for the libnpjp2.so:

# execstack -c /usr/java/jdk1.6.0_18/jre/lib/i386/libnpjp2.so


(Don't do execstack on your symbolic link or it will copy the real file to replace the symlink.)

But after further research, I found that it may be related to a policy issue of SELinux. And upgrade selinux-policy would solve the problem. Ref.

https://bugzilla.redhat.com/show_bug.cgi?id=533486

Monday, February 1, 2010

網癮戰爭

引自維基百科:
《網癮戰爭》是中國大陸個人組織製作的網路視訊,整部作品以網路遊戲《魔獸世界》為藍本,由玩家遊戲中人物「出演」,視訊畫面《魔獸世界》里的遊戲場景截取編輯而成。電影主要反映出玩家對於遊戲審批和主流媒體不公正報導的不滿,並調侃電擊治網癮的楊永信。

這裏是Youtube上的版本

看完後,我有很沉重的感覺,上次有這個感覺應該是看six four片段時吧……

雖然主題是惡攪,我也沒有玩過魔獸世界,我一直到很後來才聽說到有關它在中國的風風雨雨,不過這套片所描寫的卻是2009年在社會中發生的種種不平事。片中人物的吶喊,就是他們對這個政府不平的制度下的吶喊。雖然沒有流血,沒有死人,但是這件事和六四是相似的地方是:高官們的權力爭鬥,被害的是小市民,所有的反對聲音被打壓,大家只能在被和諧的環境下默默地生活著。

我建議香港人,都看一看這部電影。雖然可能很多地方不明白(網上有解說),但聽聽內地網民的呼聲。

還有,那些在香港抗議這個抗議那個的人,來大陸吧,這裏才是問題的核心,別浪響時間在香港那個傀儡政府上。孫中山當年也是人在香港,志在中國。各位年青的香港人,放眼中國吧,這可能就是香港的“歴史使命”。

說多了。

Wednesday, October 14, 2009

Convert ogg to mp4

Recently I bought a new G-phone (HTC Hero) which is the actually the first smart phone for me (finally...) I can download a lot of interesting program from Android Market to it.
And one thing I want to do is downloading some training video to the phone so that I can see it in the subway. But it seems that there are no OGG-ready video player in Android Market yet (may be I should write one?). So I have to convert ogg video to mp4.
I search for such application on web but I find the most simple way is using command line:
# ffmpeg -s vga -i video.ogg video.mp4
And the converted video can play on my G-phone seamlessly.
ffmpeg is a famous video libraries for Linux which is available in RPM format in DAG repo.

Friday, July 17, 2009

Google reader public page

I like to use google reader to read blog post and I would share some articles I like. If you are interested, you can have a look:

http://www.google.com/reader/shared/00610968397564927697

Monday, June 8, 2009

ksar: a sar grapher: usage

If you are the first time user of kSar, you can unzip it and start it in Linux by

# unzip kSar-5.0.6.zip
# cd kSar-5.0.6
# sh run.sh

It should able to start the GUI if the java is in your path. If it is not, you can set $JAVA_HOME first. E.g.:

# export JAVA_HOME=/usr/java/jdk1.5.0_08
# sh run.sh

And then you can try everything in the GUI.

But if you are a heavy user of kSar like me, you should learn this:

# sh run.sh -input /var/log/sa/sar13

And there are many others useful command line argument. You should have a look to them by:

# sh run.sh -help

Tuesday, June 2, 2009

ksar: a sar grapher

I use kSar for more then a year in my daily Linux support life. It is really useful (and saved my life for several times). But I haven't see much articles on web that talk about it. So I would like to write a simple introduction by myself.


kSar is a Java-based standalone application, which can read and graph the "sar" file generated by sar from Solaris, Linux, AIX and HP-UX system. Here are some advantage of kSar:

1. Multiple Platform
Because it is Java-based, it can run on many platforms (include Windows, but I have not tested). It is useful for me because I can study the sar files from whatever OS/platfrom on the platform I am using.

2. Dynamic graph + PDF export
It makes use of jfreechart library such that we can zoom-in the graph, while it can also output the graph in pdf, jpg, png and even csv format. It is useful for me to generate reports to customers. Moreover, you can add background (e.g. company logo) in the output graph.

3. Some useful extensions
It is open-source. And I have added several patch to add some common extended statistics on Linux system like "memused with buffer adjusted", stacked memory graph and system restarted marker (add in ksar-5.0.7).

4. Real time statistics
Other then reading existing sar file, it can get the output from command line or ssh command to display real time statistics.

5. Compare two graph
It can load two sar files and view it together for easy comparison, also you can compare two graph in the sar file.


I will talk about the usage of kSar soon.