Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64386
  • 博文数量: 21
  • 博客积分: 100
  • 博客等级: 民兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-30 09:56
文章分类

全部博文(21)

文章存档

2013年(18)

2012年(3)

我的朋友

分类: LINUX

2013-08-09 10:48:07


点击(此处)折叠或打开

  1. #!/bin/bash
  2. ###############################################################
  3. #The : JiangFeng.Cai     #
  4. #From: Baustem
  5. #Time: 2010-09-14                      #
  6. #                        #
  7. #------------------------------------------------------------ #
  8. #Change history
  9. #
  10. #
  11. #
  12. ###############################################################

  13. ##############################################
  14. #    function name: chkNfsSmb
  15. #    function args:
  16. #
  17. ###########################################

  18. function chkNfsSmb
  19.     {
  20. rpm -qa|grep -q ^nfs
  21. if [ ! $? -eq 0 ];then
  22.     echo service "nfs" not
  23.     exit 200
  24. fi
  25. rpm -qa|grep -q samba
  26. if [ ! $? -eq 0 ];then
  27.     echo service "samba" not
  28.     exit 201
  29. fi
  30.     }
  31.     
  32. #############################################
  33. # function name: AddUser
  34. # function args: 1.AddUser username
  35. #
  36. ############################################
  37. function AddUser {

  38. if [ $# -eq 0 ];then
  39.      echo "##############################"
  40.     echo "usge:    ./Adduser.sh "
  41.      echo "##############################"
  42.     exit 11    
  43. fi

  44. NewUser=$1

  45. TestUser=`cat /etc/passwd | grep -q ^'${NewUser}{1,1}';echo $?`
  46. if [ ${TestUser} -eq 0 ];then
  47.      echo "##############################"
  48.     echo "Existing users"
  49.      echo "##############################"

  50.     exit 12
  51. fi

  52. if [ $# -eq 1 ];then
  53.     useradd ${NewUser}
  54.     echo 123456 | passwd --stdin ${NewUser}
  55. fi
  56.     }


  57. #############################################
  58. # function name:UserDir
  59. # function args:1.UserDir userdir
  60. #
  61. #
  62. ############################################
  63. function UserDir {

  64. UserPath=$1

  65. TestPath=`ls -l /opt/ |grep -q '${UserPath}{1,1}'$ ; echo $?`

  66. if [ ${TestPath} -eq 0 ];then
  67.     echo "Directory exists."
  68.     exit 21
  69. fi

  70. if [ $# -eq 1 ];then
  71.     mkdir /opt/${UserPath}
  72.     chmod 755 /opt/${UserPath}
  73.     chown ${UserPath} /opt/${UserPath}
  74. fi    
  75.     }


  76. ############################################
  77. # function name: SmbUser
  78. # function args: 1.SmbUser username
  79. #
  80. ###########################################
  81. function SmbUser {

  82. NewUser=$1
  83. SmbPath=/etc/samba
  84. Smbconfig=${SmbPath}/smb.conf

  85. TestSmbuser=`cat ${Smbconfig} |grep -q ^'\['${NewUser}'\]';echo $?`

  86. if [ ${TestSmbuser} -eq 0 ];then
  87.     echo "##############################"
  88.     echo "The user configuration exist."
  89.     echo "##############################"
  90.     exit 31
  91. fi

  92. if [ $# -eq 1 ];then
  93.     echo -e "[${NewUser}]"        >> ${Smbconfig}
  94.     echo -e "    "        >> ${Smbconfig}
  95.     echo -e " ;browseable = yes"    >> ${Smbconfig}
  96.     echo -e " path = /opt/${NewUser}"    >> ${Smbconfig}
  97.     echo -e " writable = yes"        >> ${Smbconfig}
  98.     echo -e " valid users = ${NewUser}"    >> ${Smbconfig}
  99.     echo "##############################################"
  100.     echo "# Please input SMB password of user."     #
  101.     echo "##############################################"
  102.   ( echo ${password} ; echo ${password} ) | smbpasswd -s -a ${NewUser}
  103. fi
  104.     }


  105. #############################################
  106. # function name: NfsUser
  107. # funciton args: NfsUser username
  108. #
  109. #############################################
  110. function NfsUser {

  111. NewUser=$1
  112. NfsPath=/etc
  113. Nfsconfig=${NfsPath}/exports
  114. if [ $# -eq 1 ];then
  115.     echo -e "/opt/${NewUser}            192.168.*.*(rw,insecure,async,no_root_squash)"            >> ${Nfsconfig}
  116. fi
  117.     }

  118. #ok,let's begin {

  119. if [ $# -ne 1 ];then
  120.     echo "uage:    ./Adduser "
  121.     exit 100
  122. fi
  123.     
  124. WHO=`whoami`
  125. if [ ${WHO} != "root" ];then
  126.     echo "sorry,you not root!"
  127.     exit 101
  128. fi

  129. NewUser=$1
  130. UserPath=$1
  131. password=123456

  132. chkNfsSmb

  133. AddUser ${NewUser}

  134. if [ $? -ne 0 ];then
  135.     echo "Users to add failure.!"
  136.     exit 102
  137. fi

  138. UserDir ${UserPath}

  139. if [ $? -ne 0 ];then
  140.     echo "Directory add failure.!"
  141.     exit 103
  142. fi

  143. SmbUser    ${NewUser}

  144. if [ $? -ne 0 ];then
  145.     echo "smbuser add failure!"
  146.     exit 104
  147. fi

  148. NfsUser ${NewUser}

  149. if [ $? -ne 0 ];then
  150.     echo "nsfuser add failure!"
  151.     exit 105
  152. fi

  153. if [ $? -eq 0 ];then
  154.     echo "###########################################"
  155.     echo "#    UserName:    ${NewUser}"
  156.     echo "#    SmbPath:    /opt/${NewUser}"
  157.     echo "#    NfsPath:    /opt/${NewUser}"
  158.     echo "###########################################"
  159. fi

  160. #The end    }


阅读(612) | 评论(0) | 转发(0) |
0

上一篇:自动创建vsftp虚拟用户

下一篇:自动ssh

给主人留下些什么吧!~~