利用cyramd批量添加用户
时间:2007-03-16 来源:Erick_Kong
Postfix终于配好并能正常工作(王兴宇的文档还有有几处有问题,但还是要感谢他,稍后整理出来),但发现不能批量添加用户,往数据库中批量插入数据还比较简单,但创建文件夹和发配限额就比较困难了,搜了一篇关于shell编程的文档,现学现卖,写了以下的利用cyradm批量添加用户的shell,程序如下:
#===========add_user.sh==============
#!/bin/bash
if (( $# != 4 ))
then
echo " usage: error param "
exit 1
fi if [ -f "$4" ]; then
echo "$4 is a file"
else
echo "$4 is not a file"
exit 1
fi inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile #file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile cyradm --user $1 --password $2 $3 <&8 >&7 & #tail -f $outputfile & while read data; do
echo "cm user/$data" >> $inputfile
echo "sq user/$data STORAGE 10485760" >> $inputfile
done < $4 #红色字体为邮箱限额,可以自己改
#============ end ============ 测试数据 #===========data.txt============== user1 user2 user3 #============ end ============ 如username:cyrus password:cyrus servername:localhost 则运行命令: ./add_user.sh cyrus cyrus localhost data.txt 这样就添加了名为user1,user2,user3的用户,用户限额为10485760
#!/bin/bash
if (( $# != 4 ))
then
echo " usage: error param "
exit 1
fi if [ -f "$4" ]; then
echo "$4 is a file"
else
echo "$4 is not a file"
exit 1
fi inputfile=in
outputfile=out
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile #file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile cyradm --user $1 --password $2 $3 <&8 >&7 & #tail -f $outputfile & while read data; do
echo "cm user/$data" >> $inputfile
echo "sq user/$data STORAGE 10485760" >> $inputfile
done < $4 #红色字体为邮箱限额,可以自己改
#============ end ============ 测试数据 #===========data.txt============== user1 user2 user3 #============ end ============ 如username:cyrus password:cyrus servername:localhost 则运行命令: ./add_user.sh cyrus cyrus localhost data.txt 这样就添加了名为user1,user2,user3的用户,用户限额为10485760
相关阅读 更多 +