批量編碼轉換腳本cp936轉utf8

    根據行政部需求,需要把samba中共享的文件夾名稱由原來的英文 "share" 改成中文的 "行政部" 幾個字.
    samba配置的是Win2003域控驗證, 原來在samba中設置的編碼爲 cp936, 在samba的共享的文件夾中均能夠正常顯示中文。

  1. # 20080816 ritto. 
  2. [global
  3.    workgroup = SBZ 
  4.    server string = mis 
  5.    password server = 192.168.5.10 
  6.    encrypt passwords = yes 
  7.    realm = SBZ.COM 
  8.    security = ads 
  9.    idmap uid = 16777216-33554431 
  10.    idmap gid = 16777216-33554431 
  11.    winbind separator = / 
  12.    template homedir = /home/%D/%U 
  13.    template shell = /bin/bash 
  14.    #template shell = /sbin/nologin 
  15.    winbind use default domain = true 
  16.    winbind offline logon = true 
  17.    winbind enum users = yes 
  18.    winbind enum groups = yes 
  19.  
  20.    smb passwd file = /etc/samba/smbpasswd 
  21.    nt acl support = yes 
  22.    passwd program = /usr/bin/passwd %u 
  23.    passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successful 
  24.  
  25.    disable spoolss = yes 
  26.    log file = /var/log/samba/%m.log 
  27.  
  28.    dos charset = cp936 
  29.    unix charset = cp936 
  30.    display charset = cp936 
  31.  
  32.    wins server = 192.168.5.10 

    • [share]
    •         comment = share
    •         inherit acls = yes
    •         path = /data0/share
    •         force user = share
    •         force group = share
    •         force create mode = 0664
    •         force directory mode = 0775
    •         public = no
    •         valid users = sbz.com/ritto.zhao,sbz.com/eva.huang
    •         write list =  sbz.com/ritto.zhao,sbz.com/eva.huang

 

在上面的 [share] 直接改成 [行政部]之後,發現 samba不能啓動了,查來查去才發現是samba不認中文,最後將samba中指定的編碼改成utf8, 纔可以正常啓動.

更改的部分如下: 

  1.    dos charset = UTF8 
  2.    unix charset = UTF8 
  3.    display charset = UTF8 
  4. ...... 
  5. [行政部] 
  6.         comment = 行政部 
  7.         inherit acls = yes 
  8.         path = /data0/share 
  9.         force user = share 
  10.         force group = share 
  11.         force create mode = 0664 
  12.         force directory mode = 0775 
  13.         public = no 
  14. valid users = sbz.com/ritto.zhao,sbz.com/eva.huang 
  15.         write list =  sbz.com/ritto.zhao,sbzcom/eva.huang 

 改好之後,samba支持中文了,也可以正常啓動了。

可是,之前定義爲cp936時,共享文件夾中的一些帶中文的文件及文件夾全部亂碼了,不能顯示顯示了。

於是,需要將之前的文件編碼由cp936改成utf8了.

腳本如下(網上搜集的,很好用): 

  1. #/bin/sh 
  2. var=0 
  3. echo $var 
  4. execing () { 
  5. local dir=$1 
  6. var=`expr $var + 1` 
  7. echo $var $dir 
  8. shift 
  9. while [ "$1" ] 
  10. do 
  11.     echo $dir/$1 
  12.     if [ -d "$dir/$1" ] 
  13.     then 
  14.         execing $dir/$1 `ls $dir/$1` 
  15.     fi 
  16.      convmv --notest -f cp936 -t utf8 $dir/$1 
  17.     shift 
  18. done 
  19. execing $1 `ls $1` 

轉換正常,文件又恢復成正常的中文了,哈哈

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章