auto mount windows shares on linux filesystem


如何讓unix可以自動掛載windows分享資料夾:

實例: Linux CentOS 5.4 + Windwos XP
目的: 要將Windows主機smbhost所分享出來的share資料夾,
其存取帳號為user,密碼為pass,
以唯讀,uid=xxx,gid=yyy身份
掛載在Linux主機的/mnt/smbhost/share目錄上供存取
方法:
1.root建立linux掛載點
#mkdir /mnt/smbhost

2.root修改linux自動掛載相關組態檔,credentials帳密另存其他位置
#vi /etc/auto.master
/mnt/smbhost /etc/auto.smbhost
#vi /etc/auto.smbhost
share -fstype=cifs,ro,noperm,credentials=/root/smbhost.autofs,uid=xxx,
gid=yyy ://smbhost/share
#vi /root/smbhost.autofs
username=user
password=pass

3.root保護linux自動掛載相關組態檔
#chmod 600 /etc/auto.smbhost /root/smbhost.autofs

4.重新啟動自動掛載服務autofs
#/sbin/service autofs restart

5.一般用戶利用cd進到自動掛載目錄取用資源
> cd /mnt/smbhost/share

6.採用自動掛載前可先用如下samba客戶端指令測試遠方資料夾的帳密及內容正確與否:
> smbclient -L smbhost -U user # 以帳密user/pass,列出smbhost主機有何分享資料夾
Password:

> smbclient '//smbhost/share' -U user # 以帳密user/pass,連上分享資料夾//smbhost/share
Password:
Domain=[SATURN] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \> help # 列舉可用指令
smb: \> ls # 列舉目錄內容
smb: \> cd folder # 切換到foler資料夾
smb: \foler\> ls

參考:
http://wiki.centos.org/zh-tw/TipsAndTricks/WindowsShares
http://linux.vbird.org/linux_server/0370samba.php

turn old pc to ad hoc desktop connectors


想要善用舊電腦,最佳方法不外是拿來當專用伺服器或客戶端使用.
以下介紹如何利用thinstation軟體,製作專用桌面連接器.
特色如下:
1.提供rdp/vnc/xdm協定的連線客戶端程式,可連接windows/unix桌面.
2.可製成iso映像檔,配合grub2,從硬碟開機(本文採用);
或直接syslinux安裝到硬碟,從硬碟開機(待嚐試).
3.硬碟只耗掉100MB空間,適用於硬碟容量少之舊型電腦.
4.記憶體只耗掉100MB,適用於記憶體容量少之舊型電腦.
5.提供各種顯示卡及網路卡驅動程式,適用於舊型電腦.

注意:安裝grub2是為了能從硬碟的iso檔啟動開機,
目前支援grub2的為ubuntu 10.04 LTS以上,
故首先安裝ubuntu軟體.以下操作皆在ubuntu上進行.

A.安裝ubuntu,供切割硬碟及安裝grub2
從 http://www.ubuntu.com/download/ubuntu/download
選擇 ubuntu 10.04 LTS, 32-bit (recommended) 下載iso,約686MB
燒錄成光碟,從光碟開機進入LiveCD,不需安裝ubuntu到硬碟.

B.製作一塊>=100MB空間的硬碟切割,供安裝grub2及iso用
從System/Administration/Partition Editor選單,開啟硬碟切割程式.
利用調大小/搬移(Resize/Move),新增(New),格式化(Format To)操作,
找出一塊>=100MB空間,格式化成ext3檔案格式,以下假設該空間為 /dev/sda2.

C.安裝grub2,供硬碟iso開機用
從Applications/Accessories/Terminal選單,開啟終端機.
利用如下指令安裝grub2,
> sudo -s
# mount /dev/sda2 /mnt
# grub-install --no-floppy --root-directory=/mnt /dev/sda
本指令將在sda硬碟的mbr安裝grub2開機程式,
並在/mnt/boot/grub/*產生grub2開機所需相關檔案,
grub2組態檔為/mnt/boot/grub/grub.cfg,稍後再手動補充
# mkdir /mnt/boot/iso

D.安裝thinstation軟體及製作thinstation.iso
D1.下載Thinstation-2.2.2g.tar.bz2軟體,約101MB,
http://sourceforge.net/projects/thinstation/files/thinstation/thinstation-2.2/Thinstation-2.2.2g.tar.bz2/download
D2.解開軟體
# tar jxvf Thinstation-2.2.2g.tar.bz2
D3.修改組態檔1,設定顯示卡,網路卡,聲音卡等驅動程式及套件
# vi Thinstation-2.2.2g/build.conf
D4.修改組態檔2,設定桌面連線程式,網路連線組態,儲存體路徑等
# vi Thinstation-2.2.2g/thinstation.conf.buildtime
系統可以有很多個螢幕(SCREEN),螢幕相當於桌面,預設SCREEN=0;
每個螢幕可以有1,2,3,4四個工作區(WORKSPACE),工作區相當於桌面頁籤,預設WORKSPACE=1;
每支程式跑起來稱作一個連線(SESSION),
利用SESSION_#_TYPE設定桌面程式圖示供點選時,每個連線編號(#)必需不同.
D5.製作 .iso
# ./Thinstation-2.2.2g/build
建立包含如上開機,桌面,網路所需開機光碟映像檔thinstation.iso
此.iso檔案大小取決於Thinstation-2.2.2g/build.conf選用模組多寡.
正常70~80MB左右.
# cp Thinstation-2.2.2g/boot-images/iso/thinstation.iso /mnt/boot/iso/
將開機光碟映像檔thinstation.iso 拷貝到 grub2 開機硬碟切割中.

E.編輯grub2的grub.cfg開機選單,供硬碟啟動thinstation.iso之用
# vi /mnt/boot/grub/grub.cfg
set timeout=5
set default=0
menuentry "Thinstation-2.2.2g-Customed-LiveCD" {
loopback loop (hd0,2)/boot/iso/thinstation.iso
linux (loop)/vmlinuz load_ramdisk=1 ramdisk_blocksize=4096 root=/dev/ram0 ramdisk_size=120000 splash=silent gfxpayload=1024x768 console=ttyS3
initrd (loop)/initrd
}

menuentry "ubuntu-9.04-desktop-i386.iso" {
loopback loop (hd0,2)/boot/iso/ubuntu-9.04-desktop-i386.iso
set root=(loop)
linux /casper/vmlinuz boot=casper iso-scan/filename/boot/iso/ubuntu-9.04-desktop-i386.iso
initrd /casper/initrd.gz
}

menuentry "Windows XP" {
set root=(hd0,1)
chainloader +1
}

menuentry "reboot" {
reboot
}

以上假設第1顆硬碟sda的第1切割sda1即(hd0,1)安裝Windows XP,
第2切割sda2即(hd0,2)安裝grub2開機系統及ubuntu 9.04,thinstation兩種.iso.

# reboot
重新開機之後,就會看到4個選項,如下,



預設5秒進入第1個選項即thinstation.iso.
進入thinstation畫面如下,



每種連線協定皆有兩個圖示,有加(fs)者為全螢幕(fullscreen).
可點選其中的MS Windows圖示,
在Server Name or IP Number,輸入欲連線的Windows IP,
即以rdesktop套件,走rdp協定,連線到Windows桌面.
若想要全螢幕,可在Options,輸入 -f 參數,事後即可用Ctrl-Alt-Enter作全半螢幕切換.

註1: grub2的grub.cfg選單本來設計成程式自動產生,但這裏只用其開機掛載iso功能,
故為求精簡,直接手動編輯.
註2: 此>=100MB硬碟切割其實適合安裝於任何開機硬碟中,
所佔空間少,基本的mount,ssh.scp,e3vi功能也都有,可當作救援開機碟用.
前提是grub2要安裝佔用開機硬碟的mbr (master boot record)即可.
註3:從左下Start功能表,開啟rxvt終端機,用free指令,可觀察目前所用記憶體.
正常只用rdesktop應該不超過100MB,
若你當初在Thinstation-2.2.2g/build.conf選用較多模組,所用記憶體可能到達170MB.

ssh without password


使用ssh協定,要登入遠方主機或拷貝遠方檔案時,有免去輸入帳密方法,如下:
原理: 將自己的公開金鑰(localhost:~/.ssh/*.pub)加入
遠方主機的授權金鑰檔內(remotehost:~/.ssh/authorized_keys)

工具: 可利用以下reg_ssh_key.sh批次檔作登入及加入動作.
以後,利用終端機ssh remotehost或scp file remotehost:時,就可以免問帳密.

方法: localhost> vi reg_ssh_key.sh # 建立註冊批次檔,user為遠端主機帳號
cat ~/.ssh/*.pub | ssh user@$* "cat >> .ssh/authorized_keys"

localhost> sh reg_ssh_key.sh remotehost # 利用註冊批次檔,向遠方主機remotehost註冊
金鑰
Password:

localhost> ssh remotehost # 測試ssh自動登入遠方主機,不問密碼

remotehost>

註:
1.遠方主機的檔案目錄必需設定權限如下:
remotehost:~/.ssh 目錄權限為711,即己/群/他權限分別為rwx/x/x,
remotehost:~/.ssh/authorized_keys 檔案權限為644,即己/群/他權限分別為rw/r/r,

2.個人金鑰生成法:
若有ssh-user-config指令,以問答方式產生個人金鑰,
若無該指令,可用ssh-keygen指令產生

3.本地/遠方所需ssh組態檔如下,
客戶端: /etc/ssh_config 或 /etc/ssh/ssh_config
伺服端: /etc/sshd_config 或 /etc/ssh/sshd_config

------------------ reg_ssh_key.sh ----------------------
#
# http://josephjiang.com/article/understand-ssh-key/
#
# run to get /etc/ssh_config, /etc/sshd_config
# ssh-host-config
# run to get ~/.ssh/identify.pub, id_rsa.pub, id_dsa.pub
# ssh-user-config
# #ssh-keygen -t rsa1
# #ssh-keygen -t rsa
# #ssh-keygen -t dsa
# chmod 711 remote:~/.ssh
# chmod 644 remote:~/.ssh/authorized_keys
#
cat ~/.ssh/*.pub | ssh user@$* "cat >> .ssh/authorized_keys"

transfer over 1gb large files over internet via ssh

當你有大於 1GB 的資料要在網路上傳輸, 利用現有大部份的 httpd, ftpd 等伺服器都沒辦法識別傳輸這類大檔案。

假設大檔案位於本地端 source@local 帳號下,你要傳輸到遠地端 destin@remote 帳號下。 則你可以使用如下任一方法:

其中,port_num 為 ssh 的 tcp 連線埠號,預設值為22。
path/from/file 為 source@local 帳號下的大檔案。
path/to/file 為 destin@remote 帳號下打算存放大檔案的位置

A.利用 sftp
remote> sftp  -oPort=port_num  source@local:path/from/file

B.利用 scp
remote> scp  -P port_num  source@local:path/from/file  path/to/file
或
local> scp  -P port_num path/from/file destin@remote:path/to/file

C.利用 rsync+ssh,具續傳功能,不怕中途斷線
remote> rsync  --copy-links  --progress  --partial  --append \
  -vtpre 'ssh -p port_num '  source@local:path/from/file  path/to/file
或
local> rsync  --copy-links  --progress  --partial  --append \
  -vtpre 'ssh -p port_num '  path/from/file  destin@remote:path/to/file


上述3方法適用於 Linux 或 Cygwin 平台。
尤其最後一個方法的 rsync 支援中斷續傳功能,很適合大資料夾之傳輸。

註:
1.若只想在本機硬碟之間進行大量資料夾之備份,也可使用如下 rsync 語法,少掉 e 參數:
   $ rsync --stats --progress --partial --append \
       -vtpr  path/from/folder/  path/to/folder/
   或
   $ rsync -aP path/from/folder    path/from/folder/  # 來源放入去處
   $ rsync -aP path/from/folder/   path/from/folder/  # 來源覆寫去處
       # -a 包含 -r, -l (保留軟連結), -p, -t, -g (保留群組), 
       #        -o (保留擁有者), -D (保留設備檔)
       # -P 包含 --progress, --partial

2.rsync 參數說明:
   rsync source@local:path/from/folder/  destin@remote:path/to/folder/
     --copy-links  將符號連結(軟連結或捷徑)進行實體拷貝
     --progress   顯示傳輸進度
     --stats     顯示檔案統計資訊
     --partial   傳輸中斷時,去處端將留下接收一半的檔案
     --append    傳輸時,遇到去處端長度有較小的檔案將自動從來源端補齊剩餘長度
     --rsync-path="sudo rsync"   讓遠方切換特權模式,取得特權目錄內容
     -v    傳輸時列印檔名訊息
     -t    去處端維持來源端的修改時間
     -p    去處端維持來源端的存取權限
     -r    傳輸包含所有子資料夾
     -e 'ssh -p port_num'  利用後面的指令字串進出連線傳輸
     -n    乾跑,只看清單,不實際拷貝

3.如果整理重複目錄時,只想找出本機硬碟之間兩目錄的差異,
  可自訂如下批次檔 ~/bin/backup.sh:
    #!/bin/bash
    #
    #rsync --stats -hlPrtv source/ destin/
    # [P]: keep (partial)ly transferred files, show (progress) during transfer
    # [h]: output numbers in (human-readable) format
    # [l]: copy sym(links) as symlinks readable
    # [r]: get (recursive) into directories
    # [t]: preserve modification (times)
    # [v]: increase (verbose) level
    echo "rsync --stats --append --partial --progress -vtprn $*"
    rsync --stats --append --partial --progress -vtprn $*

  實際比對時,可利用如下指令,

    host> bash ~/bin/backup.sh    source_path/    destin_path/

  得到source_path/須要搬動到destin_path/的檔案清單。
  搬完後,source_path/ 目錄將完全包含於 destin_path/ 目錄,也就是
  前者有的後者必有,故前者目錄即使刪除也沒關係。

  又因為有參數-n,執行結果只列印差異,沒有實際搬動。
  故當兩者差異為0檔案,無須搬動,即可確認前目錄已完全同步到後目錄。
  這時就可安心刪除前目錄。

transfer from zte f188 cellphone to vista via bluetooth


zte f188手機使用藍牙傳輸檔案給vista電腦方法

如下先讓vista電腦及zte f188手機互相識別對方裝置存在
然後開始將手機資料傳到電腦:

A.ZTE F188手機:如下先發出信號,待對方補捉
[選單/電子祕書/連結/藍牙/藍牙管理器]
啟動藍牙
顯示手機
手機名稱:F188

B.VISTA電腦:如下接收信號,產生密碼,待對方確認
Bluetooth裝置/檢視/名稱
可看到F188
按下後,將電腦產生的一組密碼,輸入到手機密碼欄中
手機中將出現電腦裝置名:vista

C.開始手機往電腦傳輸
電腦先左鍵按Bluetooth裝置/接收檔案
手機再選到檔案後,選擇[發送/藍牙],即可傳送過去

combination enumerator in java


/*
  Combination.java

  generates all combinations of C(n,m) for n >= m >= 0

Usage: java Combination n m

Sample Output:
> java Combination 5 2
--- recursive one-shot generation ---
k=1 ---> {1, 2}
k=2 ---> {1, 3}
k=3 ---> {1, 4}
k=4 ---> {1, 5}
k=5 ---> {2, 3}
k=6 ---> {2, 4}
k=7 ---> {2, 5}
k=8 ---> {3, 4}
k=9 ---> {3, 5}
k=10 ---> {4, 5}
--- nonrecursive item-wise generation ---
k=1 ---> {1, 2}
k=2 ---> {1, 3}
k=3 ---> {1, 4}
k=4 ---> {1, 5}
k=5 ---> {2, 3}
k=6 ---> {2, 4}
k=7 ---> {2, 5}
k=8 ---> {3, 4}
k=9 ---> {3, 5}
k=10 ---> {4, 5}

--- Combination.java ---
*/
import java.util.Vector;
import java.util.Enumeration;

// class for generating all m-item selection sets from an n-item population set
public class Combination {
    Vector < Object > n_set; // population set of objects for combination
    int n; // population size, n >= m >= 0
    int m; // selection size

    // constructor for combination object
    //   n_set: population set of objects for combination
    //   m:  selection size
    public Combination(Vector < Object > n_set, int m) {
        this.n_set = n_set;
        this.n = n_set.size();
        this.m = m;

        if (n < m || m < 0 || n <= 0) {
            System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
        }
    }

    // generate integer objects from 1 to n
    public static Vector < Object > generateIntegers(int n) {
        Vector < Object > set = new Vector < Object > ();
        for (int i = 1; i <= n; i++) set.add(i);
        return set;
    }

    // generate integer objects from 1 to n
    public static Vector < Vector < Object >> cnm(int n, int m) {
        Vector < Object > set = generateIntegers(n);
        Combination c = new Combination(set, m);
        Vector < Vector < Object >> set_list = c.cnm();
        return set_list;
    }

    // generate all m-item selection sets from population set n_set
    //   returns set of all m-item selection sets from population set n_set
    Vector < Vector < Object >> cnm() {
        return cnm(n_set, m);
    }

    // recursive generation of all m-item selection sets from population set n_set
    //   n_set: population set
    //   m: selection size
    //   returns set of all m-item selection sets from population set n_set
    Vector < Vector < Object >> cnm(Vector < Object > n_set, int m) {
        Vector < Object > set = new Vector < Object > ();
        Vector < Vector < Object >> result_list = new Vector < Vector < Object >> ();

        int n = n_set.size();
        if (n < m || m < 0 || n <= 0) {
            System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
            return null;
        }

        // base case 1: m=0
        if (m == 0) {
            result_list.add(set);
            return result_list;
        }
        // base case 2: m=n
        else if (m == n) {
            result_list.add(n_set);
            return result_list;
        }

        // recursive call:
        Vector < Vector < Object >> result_with_first = new Vector < Vector < Object >> ();
        Vector < Vector < Object >> result_without_first = new Vector < Vector < Object >> ();

        Vector < Object > n_minus_1_set = new Vector < Object > (n_set);
        n_minus_1_set.removeElementAt(0);
        result_with_first = cnm(n_minus_1_set, m - 1);
        result_without_first = cnm(n_minus_1_set, m);
        for (Vector < Object > comb: result_with_first) {
            comb.insertElementAt(n_set.firstElement(), 0);
        }

        result_list.addAll(result_with_first);
        result_list.addAll(result_without_first);

        return result_list;
    }

    // get enumerator for all m-item selection sets from population set n_set
    Enumeration < Vector < Object >> enumeration() {
        if (n < m || m < 0 || n <= 0) {
            System.err.printf("combine(n=%d, m=%d): illegal n,m!\n", n, m);
            return null;
        }
        return new Enumerator();
    }

    // inner class of Combination class
    // enumerator for non-recursive generation of all m-item selection sets from population set n_set
    public class Enumerator implements Enumeration < Vector < Object >> {
        int index[];
        int index_upper[];
        boolean carry;
        boolean hasMore;
        Vector < Object > element;

        // constructor for m-item selection set enumerator
        public Enumerator() {
            element = new Vector < Object > ();
            hasMore = true;

            //carry = new boolean[m];
            index = new int[m];
            index_upper = new int[m];
            for (int i = 0; i <= m - 1; i++) {
                index[i] = i;
                index_upper[i] = n - m + i;
            }
        }

        public boolean hasMoreElements() {
            return hasMore;
        }

        public Vector < Object > nextElement() {
            int i;
            element.clear();
            for (i = 0; i <= m - 1; i++) {
                element.add(n_set.get(index[i]));
            }

            // point to next index
            carry = false;
            for (i = m - 1; i >= 0; i--) {
                int digit = index[i];
                if (digit + 1 <= index_upper[i]) {
                    index[i]++;

                    if (carry == true)
                        while (i + 1 <= m - 1) {
                            index[i + 1] = index[i] + 1;
                            i++;
                        }
                    break;
                } else
                    carry = true;
            }

            if (i < 0) hasMore = false;
            return element;
        } // end of nextElement
    } // end of enumerator class

    // main program for test
    public static void main(String args[]) {
        int n = 5;
        int m = 2;

        if (args.length == 2) {
            n = Integer.parseInt(args[0]);
            m = Integer.parseInt(args[1]);
        }

        System.out.println("--- recursive one-shot generation ---");

        Vector < Vector < Object >> set_list = Combination.cnm(n, m);
        int k = 1;
        for (Vector < Object > set: set_list) {
            System.out.printf("k=%d ---> {", k);
            boolean first = true;
            for (Object o: set) {
                if (first) first = false;
                else System.out.print(", ");
                System.out.print((Integer) o);
            }
            System.out.println("}");
            k++;
        }

        System.out.println("--- nonrecursive item-wise generation ---");

        Vector < Object > set = Combination.generateIntegers(n);
        Combination c = new Combination(set, m);
        Enumeration < Vector < Object >> e = c.enumeration();
        k = 1;
        while (e.hasMoreElements()) {
            set = e.nextElement();
            System.out.printf("k=%d ---> {", k);
            boolean first = true;
            for (Object o: set) {
                if (first) first = false;
                else System.out.print(", ");
                System.out.print((Integer) o);
            }
            System.out.println("}");
            k++;
        }
    }
}


註: 本程式使用 GitHub JavaScript code prettifier 工具標示顏色。其方法如下:
   1.參考 [Blogger] 如何在 Blogger 顯示程式碼 - Google Code Prettify
     於【Blogger 版面配置 HTML/JavaScript小工具】安裝如下套件
       <script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
   2.文章編輯再以HTML模式為程式包上如下標籤。
       <code class="prettyprint lang-java linenums"> ... </code>

ibus recovery from "no input window " error

fedora11預設安裝文字輸入系統為ibus,
於繁體中文語言登入時,ibus預設有注音及拼音兩者可正常使用,
但若用[系統/管理/新增/移除軟體]添加倉頡等輸入法,
則安裝好後,所有輸入法都會消失,只顯示"no input window"訊息.

原因可能是安裝倉頡時連帶更新的ibus-1.2有bug,
還原ibus-1.1舊設定法為
# rpm -qa | grep ibus- (先看目前裝了那些ibus套件)
# ln -s /media/Fedora\ 11\ i386\ DVD/Packages/* /var/cache/yum/fedora/packages/
(將安裝光碟套件作成捷徑,放入yum cache套件目錄中,省去再從網路抓)
# yum downgrade ibus-libs (讓yum自動檢查移除ibus-1.2相關套件,並退回ibus-libs 1.1)
Running Transaction
Installing : ibus-libs-1.1.0.20090423-1.fc11.i586 1/12
Erasing : ibus-1.2.0.20090927-1.fc11.i586 2/12
Erasing : ibus-gtk-1.2.0.20090927-1.fc11.i586 3/12
Erasing : ibus-chewing-1.2.0.20091002-1.fc11.i586 4/12
Cleanup : ibus-libs-1.2.0.20090927-1.fc11.i586 5/12
Erasing : ibus-rawcode-1.2.0.20090703-1.fc11.i586 6/12
Erasing : ibus-m17n-1.2.0.20090617-2.fc11.i586 7/12
Erasing : ibus-table-cangjie-1.2.0.20090717-2.fc11.noarch 8/12
Erasing : ibus-hangul-1.2.0.20090617-2.fc11.i586 9/12
Erasing : ibus-table-1.2.0.20091014-2.fc11.noarch 10/12
Erasing : ibus-anthy-1.1.0.20090402-1.fc11.i586 11/12
Erasing : ibus-pinyin-1.1.0.20090303-1.fc11.noarch 12/12
# yum localinstall ibus-1.1.0.20090423-1.fc11.i586.rpm
# yum localinstall ibus-chewing-1.0.10.20090523-2.fc11.i586.rpm
# yum localinstall ibus-pinyin-1.1.0.20090303-1.fc11.noarch.rpm
# yum localinstall ibus-gtk-1.1.0.20090423-1.fc11.i586.rpm
然後[系統/關機/重新啟動]
帳號登入後,再按[Ctrl-space]啟動,按[Alt+Left_SHIFT]切換,
就可看到原來的拼音及注音語言輸入列.

當然,添加的倉頡等輸入法也都跟著消失.
解決法大概只有
1.安裝依存於舊版ibus-1.1之倉頡版本.
2.乾脆不用ibus而改用原來另外一種輸入法scim.
(yum install scim-python-xingma-cangjie.i586)

vmware server 1.0.6 on centos5.4 x86_64

在64位元centos5.4上,vmware server和xen核心不相容,裝得起來,但是執行vmware會當掉.
故要在如下centos5.4上利用vmware server建立虛擬機,

[user@centos ~]$ uname -a
Linux centos.im.tku.edu.tw 2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:12:36 EST 2009
x86_64 x86_64 x86_64 GNU/Linux

測試可行安裝清單如下,

kernel-2.6.18-164.6.1.el5
kernel-devel-2.6.18-164.6.1.el5 (vmware編譯所需核心宣告檔)
VMware-server-1.0.6-91891.tar.gz (需重新自動編譯)

-- 以下清單為有需要才安裝 --
ntfs-3g-200944-e1i686.rpm (有讀寫ntfs切割才安裝,但是無法作檔案鎖定,無法跑vmware)
NVDIA-Linux-x86_64-185.18.31-pkg2.run (有geforce顯示卡才安裝,需telinit 3下,自動編譯)

tomcat6 encoding problem by GET/POST


撰寫jsp時,使用tomcat6引擎,常見接收中文出現亂碼,不像使用resin引擎方便,
這時只要作如下兩tomcat組態檔修改,
就可以接收表單的GET方式送來的中文big5碼,轉換成jsp內建的unicode.
這樣很方便作中文碼參數置入網址之測試,例如,http://host/cgi?q=%ac%ec.

/etc/tomcat6/server.xml

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="big5" />


/etc/tomcat6/web.xml

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>parameterEncoding</param-name>
<param-value>big5</param-value>
</init-param>

</servlet>

另外,發覺瀏覽器使用GET方式封裝中文參數於網址時,
有時會用big5,有時會用utf-8,視網頁如下宣告編碼(charset)而定,
<%@page contentType="text/html; charset=big5" import="java.io.*" %>
但作了如上2組態檔設定後,就只有big5送來的碼可正常轉換成unicode碼.
註:原來tomcat預設只接收"iso-8859-1"正常ascii編碼之參數.

至於表單用POST方式送來的big5中文碼參數,要正確轉換成unicode,
則.jsp程式碼需加上如下設定編碼指令才行.
request.setCharacterEncoding("big5");
query = request.getParameter("q");

參考資料:
http://minchuanwang.blogspot.com/2009/03/tomcat-post-get.html

simple notes on libsvm java

libsvm java版使用例
==================
                                             
1.libsvm程式下載點:
  http://www.csie.ntu.edu.tw/~cjlin/libsvm+zip

2.範例資料下載點:
  http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets

3.程式編譯法:
C:\libsvm\libsvm-2.89\java>javac -cp libsvm.jar *.java
產生尺度調整器svm_scale.class
    訓練器svm_train.class
    預測器svm_predict.class

4.資料採稀疏格式,一列一案例,先預測數值,再列舉所有非零(維度:值)

5.訓練測試範例
  以下範例訓練集資料: a1a.txt
  以下範例測試集資料: a1a_t.txt

A.未作尺度調整例:
A1.呼叫訓練器
    輸入訓練資料: a1a.txt
    輸出學得模型: a1a_model.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_train a1a.txt a1a_model.txt
*
optimization finished, #iter = 495
nu = 0.46026768501985826
obj = -673.0313934890871, rho = -0.6285688589260043
nSV = 754, nBSV = 722
Total nSV = 754

A2.呼叫預測器
    輸入測試資料: a1a_t.txt
    輸入學得模型: a1a_model.txt
    輸出預測結果: a1a_predict.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_predict a1a_t.txt a1a_model.txt a1a_predict.txt
Accuracy = 83.58638066933712% (25875/30956) (classification)
--
B.作尺度調整例:
B1.呼叫尺度調整器2次
     輸入訓練資料:     a1a.txt
     輸出調整模型:     a1a_param.txt
     輸出調整訓練資料: a1a_scale.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_scale -s a1a_param.txt a1a.txt > a1a_scale.txt
Warning: original #nonzeros 22249
         new      #nonzeros 181365
Use -l 0 if many original feature values are zeros

     輸入測試資料:     a1a_t.txt
     輸入調整模型:     a1a_param.txt
     輸出調整測試資料: a1a_t_scale.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_scale -r a1a_param.txt a1a_t.txt > a1a_t_scale.txt
Warning: original #nonzeros 429343
         new      #nonzeros 3807588
Use -l 0 if many original feature values are zeros

B2.呼叫訓練器
    輸入訓練資料: a1a_scale.txt
    輸出學得模型: a1a_model_scale.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_train a1a_scale.txt
 a1a_model_scale.txt
*
optimization finished, #iter = 682
nu = 0.4077289259698594
obj = -593.6459193183854, rho = -0.48104500731367267
nSV = 694, nBSV = 622
Total nSV = 694

B3.呼叫預測器
    輸入測試資料: a1a_t_scale.txt
    輸入學得模型: a1a_model_scale.txt
    輸出預測結果: a1a_predict_scale.txt
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_predict a1a_t_scale
.txt a1a_model_scale.txt a1a_predict_scale.txt
Accuracy = 84.05478744023776% (26020/30956) (classification)

--
-- 以上B相對於A,多作了輸出入範圍尺度調整,準確率略提昇.
-- 另外,A1及B2呼叫訓練器時,針對預設C-SVC學習器,
-- 若能適當作參數網格搜尋最佳化,準確率會更提昇
-- C-SVC參數有-g gamma及-c cost兩項,詳libsvm首頁guide.pdf
--  http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf
--
1. 尺度調整器選項:
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_scale
Usage: svm-scale [options] data_filename
options:
-l lower : x scaling lower limit (default -1)
-u upper : x scaling upper limit (default +1)
-y y_lower y_upper : y scaling limits (default: no y scaling)
-s save_filename : save scaling parameters to save_filename
-r restore_filename : restore scaling parameters from restore_filename

2. 訓練器選項:
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_train
Usage: svm_train [options] training_set_file [model_file]
options:
-s svm_type : set type of SVM (default 0)
        0 -- C-SVC
        1 -- nu-SVC
        2 -- one-class SVM
        3 -- epsilon-SVR
        4 -- nu-SVR
-t kernel_type : set type of kernel function (default 2)
        0 -- linear: u'*v
        1 -- polynomial: (gamma*u'*v + coef0)^degree
        2 -- radial basis function: exp(-gamma*|u-v|^2)
        3 -- sigmoid: tanh(gamma*u'*v + coef0)
        4 -- precomputed kernel (kernel values in training_set_file)
-d degree : set degree in kernel function (default 3)
-g gamma : set gamma in kernel function (default 1/k)
-r coef0 : set coef0 in kernel function (default 0)
-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
-m cachesize : set cache memory size in MB (default 100)
-e epsilon : set tolerance of termination criterion (default 0.001)
-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
-v n : n-fold cross validation mode
-q : quiet mode (no outputs)

3. 預測器選項:
C:\libsvm\libsvm-2.89\java>java -cp libsvm.jar svm_predict
usage: svm_predict [options] test_file model_file output_file
options:
-b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet

Disable UDP to solve frequent RDP disconnection

解決 RDP 遠端桌面經常斷線問題:「關閉 UDP 傳輸」 在使用 Windows 內建的 遠端桌面(RDP, Remote Desktop Protocol) 連線時,你是否也常遇到連線突然卡死、畫面凍結,或是頻繁跳出「連線已中...

總網頁瀏覽量