Utilize shell scripts,linux commands, open source tools,java, to Maximize the Power of Linux.
Focused on working with linux and shell, search engine technology including Chinese segmenter
Any questions please contact me at gmail: david.ullua

Labels

Showing posts with label working with linux. Show all posts
Showing posts with label working with linux. Show all posts

5/09/2007

"You can't load TkCximage", could not run amsn as normal user

gaim or Kopete would miss lots of messages. what's the most worse is file transfer often fails. so i tried amsn under linux as MSN messenger.

I download amsn 0.96 from linuxpackages for the slack package.
First time when i run ./amsn, it said "exec wish" failed, then I googled and installed TCL/tk in the slackware 11 second ISO file.

Then run ./amsn, it said could not find ComboBox, oh, then googled and find that the package is installed by root, and normal users does not have the rights of /usr/share/amsn/utils/combobox. So I chown the rights to a normal user. Still, it said "You can't load TkCximage, this is now needed to run aMSN. please compile amsn first..." , oh, God, the cause is /usr/share/amsn/ and all it's sub-directories doesn't have the execute permission, so can't load TkCximage.

Then I logged in xfce as root , run amsn, it works. So I tried to give all subdirectories under /usr/share/amsn/ with execute permission, ( add execute permission for all subdirectories under folder ):
#cd /usr/share/amsn/
#find ./ -type d -exec chown david.users {} \;
#find ./ -type d -exec chmod +x {} \;

then logged as normal user david, run ./amsn, it works now.

2/04/2007

使用fdisk -l 快速查找可用的移动设备(移动硬盘,优盘,SD/MMC卡等)

插入移动硬盘或者优盘以后,对于不一样的USB设备,不一样的机器,移动硬盘(或优盘)在系统中的设备标识(/dev目录下的链接)都是不一样的。

有时候是在/sdb1下面,有时候是在/sdc1, 或者/sda5下,也可能是其他的路径标识。在尝试了"mount /dev/sdxn /mnt/udisk" 3次,5次都没有找到后,任何人都可能感觉到泄气。

其实在我们可以用fdisk -l (注意是小写的-L,list的意思) 命令查看系统的所有存储设备信息。fdisk是磁盘格式化工具,所以在磁盘,包括移动存储设备还没有mount的时候,就可以检测到这些设备。

下面是我的电脑插上优盘约30秒(接上优盘后,会有片刻的检测时间)后,运行fdisk -l的结果:
Disk /dev/sda: 512 MB, 512229376 bytes
9 heads, 8 sectors/track, 13895 cylinders
Units = cylinders of 72 * 512 = 36864 bytes

Device Boot Start End Blocks Id System
/dev/sda1 4 13896 500107+ 6 FAT16

Disk /dev/hda: 80.0 GB, 80023182848 bytes
255 heads, 63 sectors/track, 9728 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1736 13944388+ 7 HPFS/NTFS
/dev/hda2 1737 9729 64203772+ f W95 Ext'd (LBA)
/dev/hda5 1737 2884 9221278+ b W95 FAT32
/dev/hda6 2885 3648 6136798+ 83 Linux
/dev/hda7 3649 8512 39070048+ 7 HPFS/NTFS
/dev/hda8 * 8513 9156 5172898+ 83 Linux
/dev/hda9 * 9157 9666 4096543+ 83 Linux
/dev/hda10 9667 9729 506016 82 Linux swap

这里可以看到/dev/sda1是有盘,可以mount /dev/sda1 /mnt/udisk加载u盘。

2/02/2007

hacking linux - find an unkown command for a desired function in a special linux distribution

If you use linux everyday, sometimes you post a problem on the newsgroup, someone would tell you a command called foobar would solve the problem. But when you type foobar in terminal, it shows "-bash: foobar: command not found", then you may wondering whether linux is as good as said, or whether your distribution is as good as others, or people had given a wrong answer. Stop wondering now,

I met the problem sometimes. and got the solution by "man -k command" .

Case 1: when i use ant files to build eclipse project, error occurred as "ant: /bin/sh^M: bad interpreter: No such file or directory." , which is described on the post:
Use eclipse with ant to deploy your java project -- from beginning of env setup to ant build .

I googled and find a post on apache mailing list, people suggest use unixdos to convert text file "ant" from dos format to unix format. I type unixdos, failed with "command not found". After thinking a while, I type :
$ man -k dos |grep -i unix
ExtUtils::MM_DOS (3) - DOS specific subclass of ExtUtils::MM_Unix
fromdos (1) - convert DOS text file format to UNIX
mcopy (1) - copy MSDOS files to/from Unix
mtools (1) - utilities to access DOS disks in Unix
todos (1) - convert UNIX text file format to DOS

Yes, fromdos, it is what i am finding. here i use man and grep to find the proper command.


Case 2: I need to convert GBK encoded text file to UTF-8 format. and googled around several times, couldn't get any useful info.

%man -k convert |grep -i encoding

the command could not find any useful command, thought it a lit while, hmmm, i need a command for character conversion

%man -k convert | grep -i character
...
%man -k conversion |grep -i character

fwprintf [wprintf] (3) - formatted wide character output conversion
iconv (3) - perform character set conversion
iconv_close (3) - deallocate descriptor for character set conversion
iconv_open (3) - allocate descriptor for character set conversion
...

Yes, iconv is exactly what i need.

1/22/2007

KMail提示用户可能忘了附件的有趣功能

今天发邮件的时候,KMail居然提示我"可能有附件,要不要附加文件,还是原样发送?"
原来我的邮件的内容中含有attachment这个单词, 新建一封邮件, 里面有"附件"这个词,发送的时候KMail也提示是否要附加附件。
看起来KMail会自动检测邮件中是否有attachment,或者"附件"的单词存在,存在的时候,如果没有附加附件,在发送时会提醒是否附加附件。

这项功能实在蛮有趣的,开发者考虑的还真周到,象我这种粗心的人,曾饱受outlook发送邮件忘记附件之苦, 用KMail问题都解决了。

use crontab and mail command to backup your firefox bookmarks

add the following line to ~/cron.yourname , (yourname is your real login name)

30 12 * * * date '+%m/%d/%Y' | mail -s "bookmark"" `date '+%m/%d/%y'`" -a /home/yourname/.mozilla/firefox/68k8bqg9.default/bookmarks.html receiver1@abc.com receiver2@abc.com

maybe 68k8bqg9.default should be replaced by your actual bookmarks directory.

and run:

%crontab ~/cron.yourname

then crontab would run at 12:30 am to send firefox bookmark to your email receiver1 and receiver2.

date '+%m/%d/%Y' : to show date as "01/23/2007"

it use filter to current date as the mail's content. and use -a to specify the attachment.

it use -s spesify subject as: "bookmark"" `date '+%m/%d/%y'`" ,

here date is backquoted.

send mail with attachment in command line

if it is a normal text file, you can use redirection to send the file as
content:

mail -s "hello, david" someone@abc.com someone2@kseeker.com < attachfile

if it is a binary file, or you want to send text file as real attachment:

mail -s "hello, david" -a attachfile someone@abc.com someone2@kseeker.com

btw, mail is often the alias of mailx command in linux.

1/15/2007

vim与gvim 转换highlight的文本到html网页

今天发现用gvim居然可以把vim中着色显示的文本文件(c, php, sh, java, ...)转换成html,
且保留显示的格式和颜色,不必再为发布源代码到blog上显示格式混乱的问题了。

在gvim中点syntax => convert to html, 这样会产生一个后缀名加上html的文件,
然后保存即可(:w ).如果要对.html文件或者源文件作适当的编辑,
可以用Ctrl+ww 可以切换源文件与产生的html文件的窗口。

google 了一下"vim convert to html", 原来vim中也可以使用

:runtime! syntax/2html.vim 命令来保存按语法高亮显示的文本到html文件。

参考: http://vimdoc.sourceforge.net/vimfaq.html

24.14. How do I convert a source file (.c, .h, etc) with the Vim syntax
highlighting into a HTML file?

You can use the 2html.vim script to convert a source file into a HTML file

with the Vim syntax highlighting. Use the following command:
:runtime! syntax/2html.vim

For more information, read

:help convert-to-HTML

1/12/2007

Use eclipse with ant to deploy your java project -- from beginning of env setup to ant build

1.export project to ant build file.
2.run junit testing default build file
3.make your own build file,add unit test and junitreport to build.
4.create target of : makepackage,deployapp
5.run ant under linux terminal or win command line, or add it to scheduled tasks.
Q1: "Ant-junit, build failed: Could not create task or type of type: junit"
Q2: "ant: /bin/sh^M: bad interpreter: No such file or directory."

This tutorial shows how to use ant within eclipse to build, test, make package and deploy your app using eclipse step by step. Any questions, please feel free to contact me at david.ullua at gmail, or leave a comment. The tutorial is tested under eclipse 3.1.2, ant 1.6.5. in other higher version in the future should also works. The tutorial is oriented for readers without any knowledge about make,ant or similar build tools, while also can be as a reference for middle experienced developer.

1. export project to ant build file.
Open your java project in eclipse,select your project, right click mouse, click "export", choose "General" => "Ant BuildFiles", click "Finish", it will generate a build.xml file. The default build file includes project build target and junitreport target. we can use the default build.xml as a start.

Open build.xml, here is the first line( space after > is added for web display ) :
< basedir="." default="build" name="twoway-analyzer">< /project>
It mean the build file would take project path as basedir, and use build target as default task when running "ant" or "ant -f build.xml" in project dir without args specifying target(s).

Look at this line in build.xml:
< depends="build-subprojects,build-project" name="build">
the line means build task depends on 2 sub-tasks, and does not contain any other independent actions in the build project. that's to say, if we run "ant -f build.xml", or "ant build", it will call 2 sub-tasks: build-subprojects, build-project.

ok, now you can right click "build.xml" => "Run As" => "Ant Build" (choose the one which you can select task else it would build default tasks) , then choose targets to excute, click "run", it will run the build task.

If you met the error of "Could not create task or type of type: junit", see Q1 in the end of this article as reference.


2. run junit testing default build file
the default build file contains tests and junitreport,
you can merge seperate unit tests to one target as follows,
it combines all 4 unit tests into one target called unitTest:

<target name="unitTest">
<mkdir dir="${junit.output.dir}"/>
    <junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="com.roboo.segmenter.unitTest.DictionaryTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.MMTokenizerTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.OriginTokenizerTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.RMMTokenizerTest" todir="${junit.output.dir}"/>
<classpath refid="twoway-analyzer.classpath"/>

target>
now in eclipse you can choose unitTest to run all tests.
and you can choose junitreport, this time the report would be generated. Attention if you have chosen junitreport before unitTest, then need to adjust targets order to make sure that unitTest is done before junitreport. else the report would be generated by old data.


3.make your own build file,add unit test and junitreport to build.

every time when you export Ant Buildfiles, the default build.xml will be override. so just make your own build file. save build.xml to custbuild.xml. Also we want ant run not only as eclipse plugin but also in terminal by a single command, ok, we can add these targets to the depends of build target. find this line in custbuild.xml(which we copied from build.xml):

<target depends="build-subprojects,build-project" name="build"/>

change it to :
<target depends="build-subprojects,build-project,unitTest,junitreport" name="build"/>

now can run "ant -f custbuild.xml" in command line to run project build,unitTest and junitreport in 1 step.

when running ant, if you met the error of "ant: /bin/sh^M: bad interpreter: No such file or directory.", see Q2 as reference in the end of this article.


4.create target of : makepackage,deployapp
now we want to make a jar package for the project, then add the following target:

-- jar task to make package -->
<target name="makepackage">
< echo message="Making jar package ....."/>
< delete file="${package.name}${package.version}.jar" />
< jar destfile="${package.name}${package.version}.jar"basedir="bin" excludes="*.*,**/allwords.dict" update="false">
-- exclude normal files under bin directory -->


don't forget to add the target name to the depends for "build" target.
here package.name and package.version is predefined in the properties of the build file(after xml file's root element):
<property name="package.name" value="roboosegmenter"/>
<property name="package.version" value="1.3.2.0"/>

after making the jar package, we need to deploy it to web apps.
here app_lib_dir,tomcat_web_lib_dir is predefined in the properties of the build file(after xml file's root element)
 -- deploy segmenter lib to app_lib_dir and tomcat_web_lib -->
<target name="deployapp">
<delete>
<fileset dir="${app_lib_dir}" includes="${package.name}*jar"/> < /delete>

<copy file="${package.name}${package.version}.jar" todir="${app_lib_dir}"/>

<delete>
<fileset dir="${tomcat_web_lib_dir}" includes="${package.name}*.jar"/> < /delete

<copy file="${package.name}${package.version}.jar" todir="${tomcat_web_lib_dir}"/>
don't forget to add the deployapp target to your build define, like this:
<target depends="build-subprojects,build-project,unitTest,junitreport,makepackage,deployapp"name="build"/>


5.run ant under linux terminal or windows command line, or add it to scheduled tasks.

to build project, run unit test, make jar package and deploy app:
%ant -f custbuild.xml

to build project do not run unit test or deploy:
%ant -f custbuild.xml unitTest

to build project and run just unitTest without deploy:
%ant -f custbuild.xml build-project unittest


Q1: Ant - junit, build failed: Could not create task or type of type: junit

When running JUnit tasks in ant and you get the following error:

BUILD FAILED
path\to\...\build.xml:259: Could not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.

To fix this problem, you need to copy a JUnit.jar file to your eclipse/plugins/org.apache.ant_1.65/lib directory,
Go into Eclipse then click on Window->Preferences->ant->Runtime,
select 'Ant Home Entries (Default). Click on the button 'Add External JARs'. Locate the junit.jar file you copied, select it and hit 'OK'. Hit 'Apply', then 'OK' and try your ant task again. That should fix it.


Q2:when i run ant in unix/linux terminal it shows the following error: eclipse/plugins/org.apache.ant_1.6.5/bin/ant: /bin/sh^M: bad interpreter: No such file or directory.
A2:caused by file format under dos/windows is different to unix ,
%fromdos <> file2 or use dos2unix to change the file format.

1/11/2007

Eclipse and gaim font settings under KDE

When I opened gaim under KDE, the menus and dialogs are very ugly. And I have use eclipse day by day under KDE about 2 months. The dialog and menu, and editor fonts are fairly ugly for both English and Chinese. So I decide to change these fonts.

In eclipse Windows -> Preferences, -> General -> Appearance -> Color and Fonts, type "font" as filter , all fonts settings would be shown, dialog font, text editor font, java editor font, console fonts, etc. I change all fonts to WenQuanYi BitMap Song which support Chinese perfectly.

However in eclipse settings it's own menu font cannot be changed. after googled "elipse menu font" and "eclipse 菜单字体", found the solution:
download and install gtk-qt-engine here .

Then under the KDE Control-Center -> Appearence && Themes (外观和主题) , a submenu called "GTK Styles and Fonts" would be available, you can change the gtk Fonts here.

Now gaim also look fine.


The eclipse and gaim font problem's root cause is that :
1.Eclipse use SWT to show its UI; SWT is implemented by windows/gtk/motif
2.Running Eclipse on linux/gtk, need gtk libraries.
3.KDE is based on QT not GTK, so it need gtk-qt-engine to config GTK Style and Fonts. gtk-qt-engine is used to do it.

About Me

I am a senior developer and a team leader with 3 years development experience in Suzhou, China, focus on mobile web search, linux, Java and machine learning in NLP (natural language processing). My goal is to improve people's life with computer technology.