批量编码转换脚本cp936转utf8[原创]
根据行政部需求,需要把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, 才可以正常启动.
更改的部分如下:
- dos charset = UTF8
- unix charset = UTF8
- display charset = UTF8
- ……
- [行政部]
- comment = 行政部
- 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,sbzcom/eva.huang
改好之后,samba支持中文了,也可以正常启动了。
可是,之前定义为cp936时,共享文件夹中的一些带中文的文件及文件夹全部乱码了,不能显示显示了。
于是,需要将之前的文件编码由cp936改成utf8了.
脚本如下(网上搜集的,很好用):
- #/bin/sh
- var=0
- echo $var
- execing () {
- local dir=$1
- var=`expr $var + 1`
- echo $var $dir
- shift
- while [ "$1" ]
- do
- echo $dir/$1
- if [ -d "$dir/$1" ]
- then
- execing $dir/$1 `ls $dir/$1`
- fi
- convmv –notest -f cp936 -t utf8 $dir/$1
- shift
- done
- }
- execing $1 `ls $1`
转换正常,文件又恢复成正常的中文了,哈哈
本文出自 “ritto’s blog” 博客,请务必保留此出处http://ritto.blog.51cto.com/427838/731803