批量编码转换脚本cp936转utf8[原创]

十二 6th, 2011

根据行政部需求,需要把samba中共享的文件夹名称由原来的英文 ”share” 改成中文的 ”行政部” 几个字.
samba配置的是Win2003域控验证, 原来在samba中设置的编码为 cp936, 在samba的共享的文件夹中均能够正常显示中文。

 

 

 

 

 

 

# 20080816 ritto.
[global]
   workgroup = SBZ
   server string = mis
   password server = 192.168.5.10
   encrypt passwords = yes
   realm = SBZ.COM
   security = ads
   idmap uid = 16777216-33554431
   idmap gid = 16777216-33554431
   winbind separator = /
   template homedir = /home/%D/%U
   template shell = /bin/bash
   #template shell = /sbin/nologin
   winbind use default domain = true
   winbind offline logon = true
   winbind enum users = yes
   winbind enum groups = yes 

   smb passwd file = /etc/samba/smbpasswd
   nt acl support = yes
   passwd program = /usr/bin/passwd %u
   passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successful 

   disable spoolss = yes
   log file = /var/log/samba/%m.log 

   dos charset = cp936
   unix charset = cp936
   display charset = cp936 

   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. }
  20. execing $1 `ls $1`

转换正常,文件又恢复成正常的中文了,哈哈

本文出自 “ritto’s blog” 博客,请务必保留此出处http://ritto.blog.51cto.com/427838/731803

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
目前还没有任何评论.